Power Pivot & DAX course · Lesson 4 of 16
Calculated columns vs measures in Power Pivot
When DAX belongs in a calculated column and when in a measure, why percentage columns give wrong totals, implicit vs explicit measures, naming rules.
DAX gives you two places to put a formula: a calculated column or a measure. They use the same language, sometimes even the same functions, yet they behave completely differently. Choosing the wrong one is the most common beginner mistake in Power Pivot, and it usually shows up as a percentage column that sums to 214% or a model that takes minutes to refresh. This lesson makes the difference concrete.
Calculated columns: one value per row, stored
A calculated column adds a new column to a model table. Its formula is evaluated once for every row, when the data is loaded or refreshed, and the results are stored in the model like any imported column. It is the closest thing in the model to a formula column in an Excel table.
To add one, open Power Pivot › Manage, go to the Sales tab in Data View and click the first empty column, headed Add Column. Type the formula in the formula bar and press Enter. Then double-click the header to rename it. (You can also use Design › Columns › Add.)
= Sales[Qty] * RELATED ( Products[Cost] )
= Sales[Amount] - Sales[CostAmount]The first formula multiplies each row's quantity by the cost of that row's product, fetched along the relationship with RELATED (more in RELATED and RELATEDTABLE: working across relationships). The second subtracts. Note that column formulas refer to other columns with Table[Column] and never to cells: there are no B2 addresses in the model.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | OrderID | ProductID | Qty | Amount | CostAmount | Margin |
| 2 | 1001 | P1 | 2 | 1900 | 1400 | 500 |
| 3 | 1002 | P2 | 10 | 120 | 50 | 70 |
| 4 | 1003 | P3 | 3 | 567 | 360 | 207 |
| 5 | 1004 | P4 | 5 | 175 | 90 | 85 |
| 6 | 1005 | P5 | 4 | 1680 | 1200 | 480 |
| 7 | 1006 | P1 | 1 | 950 | 700 | 250 |
| 8 | 1007 | P2 | 20 | 240 | 100 | 140 |
| 9 | 1008 | P3 | 2 | 378 | 240 | 138 |
| 10 | 1009 | P5 | 1 | 420 | 300 | 120 |
| 11 | 1010 | P4 | 6 | 210 | 108 | 102 |
Sales with two calculated columns. Each value is computed once per row and stored.
Measures: one value per PivotTable cell, computed on demand
A measure is a named formula that is not stored row by row. It is evaluated when a PivotTable (or a cube formula) asks for it, once for each cell, using only the rows that the cell's filters let through. You create one with Power Pivot › Calculations › Measures › New Measure (details in Your first DAX measures: SUM, AVERAGE, COUNTROWS, DISTINCTCOUNT):
Revenue := SUM ( Sales[Amount] )
Gross Margin := SUM ( Sales[Margin] )
Margin % := DIVIDE ( [Gross Margin], [Revenue] )Margin % is calculated separately for each category, each region and the grand total, always as total margin divided by total revenue of the rows in that cell. That is exactly how a ratio must be aggregated.
The percentage trap
Imagine you had instead added a calculated column Margin % = DIVIDE(Sales[Margin], Sales[Amount]). Each row gets a sensible percentage. But a PivotTable must aggregate that column somehow, and none of the options is correct:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Category | Sum of Margin % column | Average of Margin % column | Margin % measure |
| 2 | Accessories | 213.8% | 53.5% | 53.3% |
| 3 | Computers | 109.8% | 27.4% | 27.3% |
| 4 | Displays | 73.0% | 36.5% | 36.5% |
| 5 | Grand Total | 396.6% | 39.7% | 31.5% |
Products[Category] on rows. Only the measure gives the true margin percentage.
The sum is meaningless (Accessories shows 213.8%). The average treats a 12-euro mouse sale and a 950-euro laptop sale as equally important, so it is skewed towards small orders: for the grand total it says 39.7%, while the real margin is 2,092 ÷ 6,640 = 31.5%. The measure divides the totals, which is the only correct way. Rule: ratios, averages of ratios and anything that must be recomputed at each level are measures.
Side-by-side comparison
| Calculated column | Measure | |
|---|---|---|
| When computed | At load and refresh, once per row | At query time, once per PivotTable cell |
| Stored in the file | Yes, uses memory for every row | No, only the formula |
| Sees | The current row (row context) | The cell's filters (filter context) |
| Use in Rows, Columns, slicers | Yes | No, only in Values |
| Use as relationship key | Yes | No |
| Typical examples | Price band, Year, Full name, Line cost | Revenue, Margin %, Customers, YTD |
| Where to create | Data View › Add Column | Power Pivot › Measures › New Measure, or the Calculation Area |
The two contexts mentioned in the table, row context and filter context, get a full lesson of their own: Filter context and row context in DAX.
When a calculated column is the right choice
- You want to slice, filter or group by the result. A PivotTable can only put columns on Rows, Columns and slicers. A price band is a classic example:
= IF ( Products[Price] >= 400, "Premium", IF ( Products[Price] >= 100, "Mid", "Budget" ) ). - You need a sort key, for example a month number used by Home › Sort by Column (see Building a calendar (date) table for Power Pivot).
- You need a key for a relationship that does not exist in the source, such as a combined Region-Year key.
- The value is fixed per row and expensive to compute repeatedly. Even then, ask whether it could be done in Power Query instead, where it is often cheaper.
SUMX (see Iterators in DAX: SUMX, AVERAGEX, MAXX and RANKX), which computes the line cost on the fly without storing it.Implicit and explicit measures
When you drag a numeric column such as Amount into Values, Excel silently creates an implicit measure called Sum of Amount. It works, but it is limited: you cannot reuse it in other formulas, it belongs to that one aggregation, and it is hard to format consistently. Measures you write yourself are explicit measures. Professionals write explicit measures for everything and hide the raw numeric columns. To see the implicit measures Excel has created, open the Power Pivot window and tick Advanced › Show Implicit Measures (switch to Advanced Mode via the File menu if the tab is missing).
Naming conventions
- Refer to columns with their table:
Sales[Amount]. - Refer to measures without a table:
[Revenue]. This makes it obvious at a glance which is which, which matters onceCALCULATEenters the picture. - Give measures business names with spaces if you like (
Margin %); the brackets handle them. - Table names with spaces or reserved words need single quotes:
'Calendar'[Date].
Amount while Sales has an Amount column, Power Pivot rejects it. Use Revenue or Total Amount.Check yourself
1. When is a calculated column evaluated?
Calculated columns are computed per row and stored.
2. Which should Margin % be?
Ratios must be recomputed from totals for each cell.
3. You want a slicer for Budget / Mid / Premium price bands. What do you create?
Slicers and rows need columns; measures can only go in Values.
4. What is an implicit measure?
Excel creates implicit measures behind the scenes.
5. How should a measure be referenced in a formula?
By convention measures are written without a table name.