How to apply conditions in Paragraph Styles

Say I’ve a paragraph (a) at the end of the page [1] with two lines still left, I mean the paragraph (a) is finished in page [1]. Now if I want to apply a condition to check the lines left after para (a) and if the lines left are less than 5 (as they’re in aforementioned condition i.e. I’ve 2 lines left), then move para (a) to Page [2]. How to do it?

I presume the question is above a new paragraph fitting in the remaining space (that is how I have answered). If not though, you may need to edit the question to be clearer about exactly what is being asked.

I’ve rephrased the question. Hope I make myself clear this time!

If you think about it, my answer below is correct. You only require the orphan option and need to set the number of lines to 5 to ensure at least this number of lines remain for a paragraph at the foot of the page.

Under the Text Flow tab > Options section > check Orphan control and Widow control options and set the value (number of lines) as required. A widow is a line that falls, in isolation, at the head of a page, while an orphan is a line that starts, again in isolation, at the bottom of a page. Turning on these options and using the default value (2) will ensure at least that number of lines remain together. There is also an option (Keep with next paragraph) that will ensure the current paragraph is kept with the following one.

This tab is available for direct formatting (Format > Paragraph…) and paragraph styles (in sidebar on the Styles & Formatting panel):

It solves my problem a bit, but still I’ve a little different situation.