AGGREGATIONS IN CALCULATED FIELDS
The concepts introduced in the “Aggregate Functions” section play an important role when it comes to calculated fields. Let's revise the calculation of the profit margin from the previous section to understand why.
The calculated field with the formula SUM([Profit])/SUM([Sales])
returns a different result than [Profit]/[Sales]
, even though both are marked as “valid” in the calculation editor. The presence of the SUM
operator makes a difference here.
If you were to leave out the SUM
operator, Tableau would still apply a sum when the field is added to the view; as you have seen, measures are usually aggregated in Tableau. But the order of the operations would be different than you want: for each row of the data, Tableau would first calculate the ratio between profits and sales, and then sum up the results. By including SUM
explicitly in the calculation, you ensure that the sum operator is applied to sales and profits separately...