You can do this with columns built from other columns. You would use a
General Program Mode template that returns a different value based on the number of pages. You would use "first_non_empty" and "cmp" to produce the correct values.
I am not currently in a position to write the template for you. Perhaps someone else can help out, should you need it.