Skip to content
Advertisement

BigQuery get row above empty column

Data:

enter image description here

What would be the best way to get the row right above the empty cell? For example, I’d like to filter out row 1 and 3 based on the fact that column_b in row 2 and 4 are empty (in this example). A simple where statement does not work unfortunately, but how would it be possible to get the row above an empty cell?

Thank you

Advertisement

Answer

I think you want lead() – but you need a column that defines the ordering of the rows, I assumed id:

Note that this will filter out the last row in the table (because it has no “next” row). If you don’t want that, we can add a little more logic:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement