Skip to content
Advertisement

Replace aggregated duplicate value in unique rows

I have a table in which each row represents a different event, with one of the fields providing a value aggregated across all the unique events that occur within that id. For example:

In the table above, 2 events occur, one at 18:00 and one at 19:00. The field value1 is a sum of the values that occur at each event, so the 18:00 event may have a value of 10 and the 19:00 event a value of 15.10, which combine to give the value of 25.10. How would one go about replacing the duplicate value1 with an empty string (not a null) such that the row is maintained:

Advertisement

Answer

Because you mentioned unique events – I assume timestamp is unique across partition. in this case – below is good option for you

if to apply to sample data from your question result is

The data type of value1 is most likely FLOAT64 so the options you have to present de-duped values is either 0 or NULL. If for some reason you need to present them as empty string you need to CAST whole field to STRING as in example below

in this case result will be

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