Sub topic 6
Building measures from other measures
This chapter assumes you can create a measure in Power BI Desktop and that you have a Sales table with a numeric SalesAmount column. You should also know that a measure's result depends on filter context, which comes from slicers, visuals, and report filters. Here you will learn to reference one measure from another so each calculation is defined once and reused.
Why reference measures
Suppose you want the average sales per order line. You need two numbers: total sales and the count of order lines. You could write the whole calculation in one formula. It is cleaner to build small measures and combine them.
Start with two base measures:
Total Sales = SUM(Sales[SalesAmount])Order Lines = COUNTROWS(Sales)Each measure now has one job and one name. Any other measure can use them.
How to reference a measure
In DAX you refer to a measure by its name in square brackets, with no table name: [Total Sales]. Columns are different. They need the table name first, as in Sales[SalesAmount]. This difference lets you tell at a glance whether a reference points to a column or a measure.
A measure that builds on the two above looks like this:
Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines])The next chapter covers DIVIDE in detail. Here the point is the structure: the new measure contains no SUM and no COUNTROWS. It only combines the two measures it references.
What happens at evaluation time
A referenced measure is not a stored number. Power BI evaluates it each time the new measure is calculated, using the filter context of the cell, card, or chart bar being drawn.
Take a matrix with Region on the rows. For the row "West":
- Power BI applies the filter
Region = West. [Total Sales]is evaluated under that filter and returns the sum for West.[Order Lines]is evaluated under the same filter and returns the row count for West.DIVIDEdivides the first result by the second.
The grand total row has no region filter, so both inputs are evaluated over all rows. The result is the total sales divided by the total order lines. It is not the average of the row values above it.
Benefits of this approach
- One definition. If the logic for "total sales" changes, you edit one measure and every measure that references it updates.
- Readability.
DIVIDE([Total Sales], [Order Lines])reads almost like the business question. - Testing. You can place each base measure in a table visual next to the ratio and check the pieces separately.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| "Cannot find name" or a red underline on `[Total Sale]` | The measure name is misspelled or the measure does not exist | Type `[` and choose the name from the suggestion list |
| `Sales[Total Sales]` is rejected | A measure was written with a table prefix as if it were a column | Write `[Total Sales]` |
| A circular dependency error | Two measures reference each other, directly or through a chain | Make one of them calculate from columns instead |
| Total row differs from the average of the rows | Ratios are not additive, and the total is calculated over all rows | Expect this. The total row is a correct ratio of totals |
Do not reference a column by mistake
A bare column name in square brackets, such as [SalesAmount], is not a safe way to write a column reference. If a measure with that name does not exist, you may get an error or, in some contexts, point at the wrong thing. Always write columns with the table name and measures without it. This habit keeps your formulas unambiguous.
Summary
- Reference a measure with
[Measure Name], and a column withTable[Column]. - Each referenced measure is evaluated under the current filter context, so the combined result changes with slicers and visuals.
- Build small base measures, then combine them. This keeps formulas short and consistent.
Exercise
You have the measures Total Sales = SUM(Sales[SalesAmount]) and Order Lines = COUNTROWS(Sales). A matrix shows Region on the rows, and the measure Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines]). For the West row, Total Sales is 600 and Order Lines is 4. For the East row, Total Sales is 400 and Order Lines is 6. What does the grand total row show, and why is it not the average of the two row values?
Show answer
The grand total row evaluates both base measures with no region filter. Total Sales is 1,000 and Order Lines is 10, so the result is 100. The West value is 150 and the East value is about 66.67. Their simple average is about 108.33, which is different, because the total row divides the combined totals instead of averaging the row results.