Sub topic 3
Why a summed ratio column gives the wrong answer
Assume you know basic Power BI navigation, star-schema relationships, and DAX functions such as SUM, IF, and column references.
Why a summed ratio column gives the wrong answer
A calculated column evaluates once for each row during model refresh. For example:
Margin % (column) = DIVIDE(Sales[Profit], Sales[Line Amount])Each row receives its own margin percentage. If you sum this column, every sale gets equal weight. A small sale counts as much as a large sale.
For an overall margin, calculate the totals first, then divide:
Margin % = DIVIDE(SUM(Sales[Profit]), SUM(Sales[Line Amount]))This measure uses the current filter context. It gives the correct result for a product, category, date, or grand total.
| Calculation | What it does |
|---|---|
| `SUM(Sales[Margin %])` | Adds row percentages and can misrepresent total margin |
| `Margin %` | Divides filtered profit by filtered sales |
Context transition: bridging row context and filter context
Row context means “the current row.” Filter context means “the rows currently allowed by filters.” A calculated column naturally has row context. A measure naturally responds to filter context.
CALCULATE can perform context transition. When it runs inside a row context, it converts the current row into filters before evaluating an expression.
Customer Sales =
SUMX(
Customer,
CALCULATE([Total Sales])
)SUMX creates row context over Customer. CALCULATE turns each current customer row into filter context, so [Total Sales] is evaluated for that customer.
Power Query and source-side columns as alternatives
Create a deterministic row-level field in Power Query when it should be prepared before loading into the model. Create it in the source database when the logic belongs to shared data preparation and can be maintained there.
Choosing between a column and a measure
- Use a calculated column for slicers, axes, filters, sorting, or row-level categories.
- Use a measure for totals, ratios, and results that must change with report filters.
- Prefer Power Query or the source for reusable transformations.
Performance and maintenance tips
Calculated columns increase model memory and refresh work because their values are stored. Measures usually use less storage and calculate when queried. Keep row-level logic upstream when practical, and use explicit measures for important business calculations.
Exercise
A report needs overall margin by category. Should you sum a row-level margin column?
Show answer
No. Use DIVIDE(SUM(Sales[Profit]), SUM(Sales[Line Amount])) so each category total is calculated from its filtered totals.