I am experiencing an issue in Google Looker Studio that I cannot logically explain and would appreciate clarification.
When I create a calculated field:
c = SUM(b) / SUM(a)
and use it in a Treemap, the resulting value is much higher than expected.
Why does SUM(a) behave differently when used inside a calculated field compared to when it is used as a standalone metric?
At what stage does Looker Studio apply aggregation and dimension filtering for calculated fields?
It seems that SUM(a) inside the calculated field is being evaluated after the chart dimensions are applied, while the scorecard shows a global aggregation — but I would like confirmation on whether this is expected behavior and how aggregation context works internally.
A scorecard uses no grouping, so Looker Studio would calculate SUM(B) overall, SUM(A) overall, then divide the two.
In a Treemap, or really any other kind of chart, you’re grouping by dimensions. So Looker Studio will calculate SUM(B) for that dimension value, then SUM(A) for that dimension value, then divide the two.
Example
Dimension
Metric A
Metric B
Calculated C (SUM(B)/SUM(A))
Campaign 1
10
100
10.00
Campaign 2
100
200
2.00
Total (Scorecard)
110
300
2.72
In this example, the scorecard would show a much lower number (2.72) than the sum of the C fields (which would be 12.00). In other words, the dimensions that you pick to group by will make a huge difference in what you’ll see in metrics, including calculated metrics.