LOOKER: Count for a subset of columns

Former Community Member
Not applicable

Given 5 columns, I need to have a count of rows matching based on 2 columns. For example:

ABCDEcountAB
ABCDE3
AZFXZ2
AZYUO2
ABQRT3
ABYRT3

I need 6th column: countAB which count  total times this combination shows up in the table results.

In sql I could make a cte with A,B, count(*) and then join the result. I have to do this for a lot of different A,B,C combos so making a pdt for each or precalculating all counts in 1 pdt might hit on performance.

 

Any ideas on how to approach this?

0 1 264
1 REPLY 1

Former Community Member
Not applicable

for future:

5k row limit applies to table calcs and merges. Merge query with separate query for A,B,count(*) was the solution. 5k on join does mean that sometimes result is null.

partition and rownum: https://www.googlecloudcommunity.com/gc/Technical-Tips-Tricks/How-do-I-do-a-ROW-NUMBER-OVER-PARTITIO...

max ts for partition*: https://www.googlecloudcommunity.com/gc/Modeling/Max-Date-Time-from-Partitioned-by-Client/td-p/57891....

Top Labels in this Space
Top Solution Authors