Sub topic 11
Percent of Parent and Percent of Grand Total
This chapter assumes you can build a matrix in Power BI Desktop and write a basic DAX measure with DIVIDE. It also assumes you know how to open the visual calculations editing experience, which earlier chapters covered.
The idea: divide by a level above
A percent-of-total calculation divides each cell by a value from a higher level of the visual's row hierarchy. The hierarchy functions COLLAPSE and COLLAPSEALL supply that higher-level value.
Suppose a matrix has Category on rows, with Subcategory nested below it, and the measure Sales Amount as the value. Each Subcategory row sits under a Category row. That Category row is its parent. The Category rows sit under the grand total.
| Function | Returns | Result when used as a divisor |
|---|---|---|
| `COLLAPSE([Sales Amount], ROWS)` | The value one level up the row hierarchy | Share of the parent |
| `COLLAPSEALL([Sales Amount], ROWS)` | The value at the top of the row hierarchy | Share of the grand total |
Percent of parent
Percent of parent = DIVIDE([Sales Amount], COLLAPSE([Sales Amount], ROWS))The second argument, ROWS, is the axis. It tells COLLAPSE to move up the row hierarchy. On a Subcategory row, the result is that Subcategory's sales divided by its Category's sales. On a Category row, the result is its sales divided by the grand total, because the grand total is that row's parent.
Percent of grand total
Percent of grand total = DIVIDE([Sales Amount], COLLAPSEALL([Sales Amount], ROWS))COLLAPSEALL ignores how deep the row is. Every row is divided by the value at the top of the hierarchy. The grand total row itself shows 100%.
Why DIVIDE
Use DIVIDE instead of the / operator. If the parent value is zero or blank, DIVIDE returns a blank instead of an error. This matters for rows with no sales.
Format the result
Both calculations return a decimal, such as 0.25. Set the data type to Decimal number and the format to Percentage in the calculation's format settings, so the cell shows 25%. Without that step, the matrix shows raw fractions.
Common errors
- No hierarchy on rows. If the visual has only one field on rows, the parent of every row is the grand total. Percent of parent and percent of grand total then match.
- Wrong axis. If you put the hierarchy on columns,
ROWSno longer points at it. UseCOLUMNSinstead, or restructure the visual. - Fields missing from the visual. Visual calculations can only use fields that are in the visual. If you remove
Sales Amount, the calculation breaks. To keep a field in use without showing it, hide it rather than removing it. - Expecting a filter effect. These results depend on the layout. If you change the nesting order of Category and Subcategory, the parent changes and so do the percentages.
Try it
- Build a matrix with Category and Subcategory on rows and
Sales Amountas a value. - Add the percent of parent calculation and format it as a percentage.
- Add the percent of grand total calculation beside it.
- Compare the two columns for a Subcategory row, then for a Category row.
Exercise
A matrix has Category on rows with Subcategory nested below it. The Bikes category has sales of 600, and its Road Bikes subcategory has sales of 150. The grand total is 1,000. What do the percent of parent and percent of grand total calculations show on the Road Bikes row?
Show answer
Percent of parent is 150 / 600 = 25%, because COLLAPSE returns the Bikes value of 600. Percent of grand total is 150 / 1,000 = 15%, because COLLAPSEALL returns the grand total of 1,000.