Search code examples
google-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-querygs-vlookup

Custom Serial Numbering Formula


enter image description here

In Google Sheets,

I want to achieve a serial numbering system in a specific manner which satisfies the following requirements:

  1. Serial Numbers should be in reverse order (In Descending Order).
  2. Only the rows which have non-empty value in Column-B will get a serial number.
  3. Adding any non-empty value in Column-B makes that row eligible for having a serial number. Hence, making Column-B blank will remove its serial number and adjust all the serial numbers on rows above the modified one.

Test Cases:

  1. Leaving a row blank in between filled rows, should not affect the serially numbered sequence.

Can anyone please provide a formula or steps to implement this feature in Google Sheets?


Solution

  • use this formula:

    =ARRAYFORMULA(IFERROR(VLOOKUP(ROW(B:B)&B:B, QUERY({SORT({ROW(
     INDIRECT("B1:B"&COUNTA(B:B))), FILTER(ROW(B:B)&B:B, B:B<>"")}, 1, 0), ROW(
     INDIRECT("B1:B"&COUNTA(B:B)))}, "select Col2,Col3", 0), 2, 0)))
    

    0