Skip to content
Advertisement

How to do the equivalent of ‘distinct’ on array field in BQ?

Let’s take the following data:

enter image description here

It can also be generated in BQ with the following statement:

How would I do the following two ‘distinct’ totals on the right of the following:

enter image description here

That is, I want to get a “total” that doesn’t double-count, or rather, only gets the distinct items based on the RowID.

Advertisement

Answer

If I understand correctly, it is the total row that you really care about. You can calculate the first two columns by unnesting both tags and payments in parallel.

Then for the total, unnest the payments without the tags:

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