Sub topic 2
Creating Your First Measure
This chapter assumes you know the Power BI Desktop interface (Report view, Fields pane, visuals). It also assumes your data model has a Sales table with a numeric SalesAmount column. You should understand tables, columns, and rows.
What you are building
A measure is a named DAX formula that Power BI evaluates when a visual needs it. It does not store a value in the table. Each time a visual, slicer, or filter changes, Power BI recalculates the measure for that context.
This chapter covers the mechanics of creating one measure. You will write a total of SalesAmount, place it in a visual, and see where measures appear in the model.
Steps to create a measure
- Open your report in Power BI Desktop and switch to Report view.
- In the Fields pane (called Data in newer versions), select the Sales table. A measure belongs to the table you select. Choose the table that fits the measure's subject.
- On the ribbon, go to Home and select New measure. You can also go to Table tools and select New measure, or right-click the table and choose New measure.
- The formula bar opens above the report canvas, with placeholder text such as
Measure =. - Replace the placeholder with your formula and press Enter.
Use this formula:
Total Sales = SUM(Sales[SalesAmount])The text before the equals sign is the measure name. The text after it is the expression. SUM adds up the values in one column, and Sales[SalesAmount] names that column by its table and column.
The new measure appears in the Fields pane under Sales, marked with a calculator icon. Columns have no calculator icon, so this is how you tell them apart.
Test the measure in a visual
A measure only produces a result inside a visual, so test it right away.
- Select an empty area of the canvas and add a Card visual.
- Drag Total Sales from the Fields pane into the card's Fields well.
- The card shows one number: the sum of SalesAmount across every row in the table.
Now add a Table or Clustered column chart, and put a column such as Product Category on the axis or rows. Add Total Sales as the value. The measure now shows a separate total for each category. You wrote the formula once, and it produced a different result for each row of the visual. The next chapter explains why.
Editing and checking your formula
Select the measure in the Fields pane to reopen it in the formula bar. You can edit the formula there and press Enter to save.
Power BI checks the formula when you press Enter. Common errors at this stage:
| Symptom | Likely cause | Fix |
|---|---|---|
| Red underline under a column name | Misspelled table or column name | Type `Sales[` and pick the column from the suggestion list |
| "The syntax of 'X' is incorrect" | Missing parenthesis or comma | Check that every opening parenthesis has a closing one |
| A measure shows as a plain number column | You created a calculated column instead | Delete it and use New measure, not New column |
| Card shows the same number in every row of a table | The measure was added to the wrong field well or the table has no relationship to the grouping column | Check the visual's fields and the model relationships |
Press Shift+Enter in the formula bar to start a new line when a formula grows long. Type // at the start of a line to add a comment.
Total Sales =
// Sum of the sales amount column
SUM(Sales[SalesAmount])Where measures live
The table you pick when creating a measure affects only where it appears in the Fields pane. The formula itself can refer to any table in the model. If you want to move the measure, select it and change Home table in the Measure tools ribbon.
Measure names must be unique across the whole model, even if the measures sit in different tables. You will return to naming and organizing in a later chapter.
What to remember
- A measure is created from New measure, not New column.
- It is typed in the formula bar as
Name = expression. - It shows a calculator icon in the Fields pane.
- It displays a value only when placed in a visual, and the value depends on that visual's filters.
Exercise
You create Total Sales = SUM(Sales[SalesAmount]) and drag it into a Card visual. The card shows 1,250,000. You then add a slicer for Year and select 2024. What happens to the measure, and does the stored data change?
Show answer
The card updates to the sum of SalesAmount for 2024 rows only, so the number is smaller. The stored data does not change. The measure holds no value of its own and is recalculated each time the filters in the report change.
Exercise
You select the Sales table, choose New column instead of New measure, and type Total Sales = SUM(Sales[SalesAmount]). How does the result differ from a measure?
Show answer
A calculated column is evaluated once per row when the data loads. Every row would show the grand total of the whole column, and the value would be stored in the model. It would not respond to slicers as a measure does. Delete it and create a measure instead.