Tableau / Basic: fields, models and views / Lesson 7
Ratios at the Intended Grain
Compare a combined rate with an equally weighted average of row rates in a Tableau view.
On this page
Lesson goals
- Define a numerator and denominator at the intended grain.
- Distinguish a ratio of sums from an average of ratios.
- Test totals and empty denominators.
Define the rate
A rate needs a qualifying numerator, an eligible denominator, a period, and a row grain. Combining groups by adding their counts answers a different question from giving every group’s rate equal weight. State which question the workbook should answer before writing a calculation or interpreting the grand total.
For this bounded Tableau lab, use two synthetic rows: group A has 8 successes out of 10 eligible cases, and group B has 18 out of 90. The snippets require these fields in a Tableau workbook and are illustrative; the public reader does not execute them.
Calculate the combined rate
The first calculation divides the sum of successes by the sum of eligible cases and returns null for a zero denominator. With both lab rows visible, the combined rate is 26 divided by 100, or 26 percent. Check the calculation under each filter and confirm that the numerator and denominator refer to the same population.
IF SUM([Eligible]) = 0 THEN NULL
ELSE SUM([Successes]) / SUM([Eligible])
END
The expression aggregates both counts in the current view context before dividing.
Compare an average of row rates
The second calculation averages the eligible row-level rates. In this fixture the rates are 80 and 20 percent, so their equal-weight average is 50 percent. It answers an average-group question, not the combined-case question. Confirm how null rows and zero denominators are treated in the actual workbook.
AVG(IF [Eligible] > 0 THEN [Successes] / [Eligible] END)
Each qualifying source row contributes one rate to the average regardless of its eligible count.
Inspect the view context
Add the group dimension and both counts to a crosstab, then compare each mark and the grand total with manual calculations. Filters can change the included population, and a relationship or join can change the grain. Reconcile source counts before attributing a difference to the calculation syntax.
Label and validate
Label the measure with its population, period, and denominator, and make null or unavailable results distinguishable from zero. Test a zero denominator, missing count, and unequal group sizes. Keep the calculation definition and source version with the workbook so a reviewer can reconstruct the result.
Common errors and fixes
The combined rate is reported as 50 percent.
- Why it happens
- Group rates were averaged equally despite different denominators.
- How to fix it
- Use combined counts for the combined-case question.
- Prevent it next time
- State the intended weighting and show counts.
An undefined rate is displayed as a measured zero.
- Why it happens
- A zero denominator was silently converted to zero.
- How to fix it
- Apply the agreed null and display policy.
- Prevent it next time
- Test empty denominators explicitly.
The rate changes after a join unexpectedly.
- Why it happens
- The join changed row grain or repeated counts.
- How to fix it
- Reconcile source keys and calculate at the intended grain.
- Prevent it next time
- Validate cardinality and totals before authoring.
2 practice exercises
1. Groups have 8/10 and 18/90 successes. What is the combined rate?
Show worked solution
Add successes and eligible counts: 26/100, or 26 percent. The 50 percent average of the two group rates answers a different question.
2. Why can a grand total differ from an average of the displayed group percentages?
Show worked solution
The total may recompute the ratio from combined counts, while the average gives each group equal weight. Inspect the calculation and denominators before deciding which result answers the question.
Key takeaways
- Define population, period, and denominator with each rate.
- A ratio of sums differs from an equal-weight average of rates.
- Test totals and empty denominators in context.