Power Pivot & DAX course · Lesson 5 of 16
Your first DAX measures: SUM, AVERAGE, COUNTROWS, DISTINCTCOUNT
Create DAX measures in Power Pivot step by step: the Measure dialog, the Calculation Area, SUM, AVERAGE, COUNTROWS, DISTINCTCOUNT, MAX and DIVIDE.
Time to write real DAX. In this lesson you create a small set of measures that almost every model needs: totals, counts, averages and distinct counts. Along the way you learn the Measure dialog, the Calculation Area, number formatting and the habit of building measures on top of other measures.
We use the three tables from The Data Model and relationships: star schema and filter direction: Sales, Products and Customers, related on ProductID and CustomerID.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | OrderID | Date | CustomerID | ProductID | Qty | Amount |
| 2 | 1001 | 2026-01-05 | C1 | P1 | 2 | 1900 |
| 3 | 1002 | 2026-01-12 | C2 | P2 | 10 | 120 |
| 4 | 1003 | 2026-01-20 | C3 | P3 | 3 | 567 |
| 5 | 1004 | 2026-02-02 | C1 | P4 | 5 | 175 |
| 6 | 1005 | 2026-02-09 | C4 | P5 | 4 | 1680 |
| 7 | 1006 | 2026-02-17 | C2 | P1 | 1 | 950 |
| 8 | 1007 | 2026-03-03 | C3 | P2 | 20 | 240 |
| 9 | 1008 | 2026-03-10 | C4 | P3 | 2 | 378 |
| 10 | 1009 | 2026-03-18 | C1 | P5 | 1 | 420 |
| 11 | 1010 | 2026-03-25 | C2 | P4 | 6 | 210 |
Sales, the fact table used for every measure in this lesson.
Creating a measure with the Measure dialog
- Click any cell in a PivotTable based on the Data Model (or any cell at all).
- Choose Power Pivot › Calculations › Measures › New Measure…. Alternatively, in the PivotTable Fields pane right-click the
Salestable name and choose Add Measure…. - Table name: choose
Sales. This is only the home table where the measure is listed; it does not limit what the formula can use. - Measure name: type
Revenue. - Description (optional):
Sum of order amounts in euros. It appears as a tooltip in the field list. - Formula: after the
=that is already there, typeSUM(Sales[Amount]). As you type, IntelliSense lists tables, columns and functions; press Tab to accept a suggestion. - Click Check formula. No errors in formula means the syntax is valid.
- Under Formatting Options choose Category: Number, Decimal places: 0 and tick Use 1000 separator (,).
- Click OK.
Revenueappears in the Sales table in the field list with an fx icon. Tick it to add it to Values.
To change a measure later, use Power Pivot › Measures › Manage Measures, select it and click Edit. The same dialog lets you delete measures.
Revenue shows it with thousands separators, so you never format the same field twice.Typing measures in the Calculation Area
In the Power Pivot window, Data View shows a grid of empty cells under each table: the Calculation Area (toggle it with Home › View › Calculation Area). Click any cell there and type the measure as Name := expression in the formula bar. This is quick when you create many measures, and you can see their grand-total values immediately. Format a measure there with the Home › Formatting buttons.
Revenue := SUM ( Sales[Amount] )The core aggregation functions
Revenue := SUM ( Sales[Amount] )
Units := SUM ( Sales[Qty] )
Orders := COUNTROWS ( Sales )
Avg Order := AVERAGE ( Sales[Amount] )
Customers := DISTINCTCOUNT ( Sales[CustomerID] )
Largest Order := MAX ( Sales[Amount] )
Avg Unit Price := DIVIDE ( [Revenue], [Units] )SUMadds a numeric column. Unlike Excel's SUM, it takes exactly one column, not a list of ranges.COUNTROWScounts the rows of a table, here the number of order lines. It is the clearest way to count transactions.COUNTcounts non-blank numbers in a column andCOUNTAnon-blank values of any type;COUNTROWSdoes not depend on any particular column being filled in.AVERAGEis the arithmetic mean of a column, blanks ignored.DISTINCTCOUNTcounts the different values in a column. A normal PivotTable cannot do this without tricks; in the model it is one function.MAXandMINreturn the largest and smallest value.DIVIDEdivides two measures and returns a blank instead of an error when the denominator is zero (Variables, DIVIDE and error handling in DAX goes deeper).
The result in a PivotTable
Insert a PivotTable from the Data Model (Insert › PivotTable › From Data Model), put Products[Category] in Rows and tick the measures:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Category | Revenue | Units | Orders | Avg Order | Customers |
| 2 | Accessories | 745 | 41 | 4 | 186.25 | 3 |
| 3 | Computers | 4950 | 8 | 4 | 1,237.50 | 3 |
| 4 | Displays | 945 | 5 | 2 | 472.50 | 2 |
| 5 | Grand Total | 6640 | 54 | 10 | 664.00 | 4 |
Products[Category] in Rows; five measures in Values. Avg Order formatted with 2 decimals.
Check the Computers row by hand: orders 1001, 1005, 1006 and 1009 are laptops and tablets, totalling 4,950 over 4 orders, so the average order is 4,950 ÷ 4 = 1,237.50. Three different customers bought them (C1 twice, C4 and C2).
Now look at the Grand Total row. Revenue, Units and Orders add up, as you would expect. Avg Order does not equal the average of the three rows: it is 6,640 ÷ 10, recomputed on all ten rows. And Customers shows 4, not 8, because customers who bought in several categories are counted once. Each measure is recalculated for the total; nothing is added up from the rows above it.
Same measures, different layout
Because measures are not tied to any layout, you can swap Category for Region and they still work. Replace the rows with Customers[Region] and add Avg Unit Price and Largest Order:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Revenue | Units | Avg Unit Price | Largest Order |
| 2 | East | 807 | 23 | 35.09 | 567 |
| 3 | North | 2495 | 8 | 311.88 | 1900 |
| 4 | South | 1280 | 17 | 75.29 | 950 |
| 5 | West | 2058 | 6 | 343.00 | 1680 |
| 6 | Grand Total | 6640 | 54 | 122.96 | 1900 |
Customers[Region] in Rows. Avg Unit Price is Revenue ÷ Units, formatted with 2 decimals.
Avg Unit Price reuses two existing measures. If you later change how Revenue is calculated (say, to exclude returns), Avg Unit Price follows automatically. Building small measures and combining them is the single best habit in DAX.
Blank results and empty rows
If a measure returns BLANK for a row item, the PivotTable hides that row (unless you tick Show items with no data in Field Settings). This is usually what you want. Be aware that COUNTROWS of an empty table returns blank, not 0. To show a zero, write Orders := COUNTROWS ( Sales ) + 0, but think twice: forcing zeros makes every product appear for every customer, which can turn a 10-row report into a 10,000-row one.
SUM and AVERAGE take a column, not an expression. SUM(Sales[Qty] * Sales[Price]) is an error. For row-by-row arithmetic, use the iterator versions SUMX and AVERAGEX, covered in Iterators in DAX: SUMX, AVERAGEX, MAXX and RANKX.Practice
- Create
UnitsandOrdersand check that their totals are 54 and 10 for the sample data. - Create
Avg Qty per Order := DIVIDE ( [Units], [Orders] )and format it with one decimal. - Create
Products Sold := DISTINCTCOUNT ( Sales[ProductID] ). Put Customers[Customer] in Rows: Anna Weber bought three different products. - Open Manage Measures and add a description to each measure.
Check yourself
1. Which formula counts the order lines in Sales?
COUNTROWS counts the rows of a table.
2. Why is Customers at the Grand Total smaller than the sum of the category rows?
Distinct counts never add up across rows.
3. In the Measure dialog, what does the Table name setting do?
It is only the home table for display.
4. What is wrong with SUM ( Sales[Qty] * Sales[Price] )?
The plain aggregators accept one column only.
5. How is a measure written in the Calculation Area?
Name, then :=, then the expression.