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.

Beginner 16 min read

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.)

DAX
= Sales[Qty] * RELATED ( Products[Cost] )

= Sales[Amount] - Sales[CostAmount]
Two calculated columns in Sales, renamed CostAmount and Margin.

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.

ABCDEF
1OrderIDProductIDQtyAmountCostAmountMargin
21001P1219001400500
31002P2101205070
41003P33567360207
51004P451759085
61005P5416801200480
71006P11950700250
81007P220240100140
91008P32378240138
101009P51420300120
111010P46210108102

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):

DAX
Revenue := SUM ( Sales[Amount] )
Gross Margin := SUM ( Sales[Margin] )
Margin % := DIVIDE ( [Gross Margin], [Revenue] )
In the Measure dialog, type the name in Measure name and the part after := in Formula.

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:

ABCD
1CategorySum of Margin % columnAverage of Margin % columnMargin % measure
2Accessories213.8%53.5%53.3%
3Computers109.8%27.4%27.3%
4Displays73.0%36.5%36.5%
5Grand Total396.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 columnMeasure
When computedAt load and refresh, once per rowAt query time, once per PivotTable cell
Stored in the fileYes, uses memory for every rowNo, only the formula
SeesThe current row (row context)The cell's filters (filter context)
Use in Rows, Columns, slicersYesNo, only in Values
Use as relationship keyYesNo
Typical examplesPrice band, Year, Full name, Line costRevenue, Margin %, Customers, YTD
Where to createData View › Add ColumnPower 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.
Tip. A calculated column on a small dimension table (Products, Customers) costs almost nothing. A calculated column on a fact table with millions of rows can double its size. In fact tables, prefer an iterator measure such as 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 once CALCULATE enters 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].
Watch out. A measure and a column cannot share the same name in the model. If you name a measure 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?

2. Which should Margin % be?

3. You want a slicer for Budget / Mid / Premium price bands. What do you create?

4. What is an implicit measure?

5. How should a measure be referenced in a formula?