Skip to content
Advertisement

Calculate a running total with a condition in BigQuery

Sorry bad topic… I need to calculate a running total but need to reset the total on a condition (when expected reached = 0). I have this table:

Expected result with running total – the condition is that while “Expected Reached” <> 0 running total should be calculated. If “Expected Reached” = 0 the running total should start over from 0:

I don’t know how to partition my window function to do this. Maybe I have to create an intermediate calculation before but Im unsure. Any suggestions?

Edit: edit2: removed my “on the fly question”.

Advertisement

Answer

Below is for BigQuery Standard SQL

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