Case 5: RAG status and ranking
A wall of numbers does not work in the monthly meeting. Every cost center gets a RAG status, and the biggest overruns come first, so the time goes to the items that really matter.
In short: write a status with several levels as SWITCH(TRUE(), condition1, "Red", condition2, "Amber", "Green"), strictest condition first. RANKX(ALL(CostCenter[CostCenter]), [Variance]) returns a rank across all cost centers.
The situation
The June report from case 1, account type Expense. The company rule: more than 10% over budget is red and gets explained in the meeting, more than 5% is amber and gets watched, everything else is green, including any underspend.
Task 1: the RAG status
Task In the June report every cost center should get a RAG status: "Red" for more than 10% over budget, "Amber" for more than 5%, otherwise "Green". Create the measure "RAG Status".
Actual 535 rows, 5 columns
| EntryID | Date | CostCenterID | AccountID | Amount |
|---|---|---|---|---|
| 1 | 23 Jan 2025 | 300 | 4000 | 88400 |
| 2 | 22 Jan 2025 | 300 | 4000 | 132600 |
| 3 | 12 Jan 2025 | 200 | 5000 | 36176 |
| 4 | 4 Jan 2025 | 600 | 5000 | 5253.5 |
| 5 | 21 Jan 2025 | 100 | 6000 | 13276.2 |
| 6 | 30 Jan 2025 | 100 | 6000 | 9613.8 |
| 7 | 16 Jan 2025 | 200 | 6000 | 49220 |
| 8 | 20 Jan 2025 | 300 | 6000 | 25440 |
| 9 | 29 Jan 2025 | 400 | 6000 | 12875 |
| 10 | 29 Jan 2025 | 500 | 6000 | 17205 |
| 11 | 10 Jan 2025 | 600 | 6000 | 5045.04 |
| 12 | 14 Jan 2025 | 600 | 6000 | 4656.96 |
Showing the first 12 of 535 rows.
Measures: [Total Actual], [Variance %]
Budget 432 rows, 4 columns
| Date | CostCenterID | AccountID | Amount |
|---|---|---|---|
| 1 Jan 2025 | 300 | 4000 | 221000 |
| 1 Jan 2025 | 200 | 5000 | 32300 |
| 1 Jan 2025 | 600 | 5000 | 5530 |
| 1 Jan 2025 | 100 | 6000 | 21000 |
| 1 Jan 2025 | 200 | 6000 | 46000 |
| 1 Jan 2025 | 300 | 6000 | 24000 |
| 1 Jan 2025 | 400 | 6000 | 12500 |
| 1 Jan 2025 | 500 | 6000 | 15500 |
| 1 Jan 2025 | 600 | 6000 | 9800 |
| 1 Jan 2025 | 100 | 6300 | 4200 |
| 1 Jan 2025 | 200 | 6300 | 7800 |
| 1 Jan 2025 | 600 | 6300 | 3600 |
Showing the first 12 of 432 rows.
Measures: [Total Budget]
CostCenter 6 rows, 3 columns
| CostCenterID | CostCenter | Division |
|---|---|---|
| 100 | Administration | Administration |
| 200 | Production | Operations |
| 300 | Sales | Sales |
| 400 | Marketing | Sales |
| 500 | IT | Administration |
| 600 | Warehouse | Operations |
Account 7 rows, 4 columns
| AccountID | Account | AccountType | AccountGroup |
|---|---|---|---|
| 4000 | Revenue | Income | Revenue |
| 5000 | Materials | Expense | Materials |
| 6000 | Salaries and Wages | Expense | Personnel |
| 6300 | Rent | Expense | Operating |
| 6500 | Travel | Expense | Operating |
| 6800 | Advertising | Expense | Operating |
| 6900 | Other Expenses | Expense | Operating |
Date 730 rows, 4 columns
| Date | Year | Month | MonthName |
|---|---|---|---|
| 1 Jan 2025 | 2025 | 1 | Jan |
| 2 Jan 2025 | 2025 | 1 | Jan |
| 3 Jan 2025 | 2025 | 1 | Jan |
| 4 Jan 2025 | 2025 | 1 | Jan |
| 5 Jan 2025 | 2025 | 1 | Jan |
| 6 Jan 2025 | 2025 | 1 | Jan |
| 7 Jan 2025 | 2025 | 1 | Jan |
| 8 Jan 2025 | 2025 | 1 | Jan |
| 9 Jan 2025 | 2025 | 1 | Jan |
| 10 Jan 2025 | 2025 | 1 | Jan |
| 11 Jan 2025 | 2025 | 1 | Jan |
| 12 Jan 2025 | 2025 | 1 | Jan |
Showing the first 12 of 730 rows.
SWITCH with TRUE() checks the conditions in order, as in the lesson on IF and SWITCH. If the 5% limit came first, Sales with 10.9% would only be amber. In the report you then color the cells with conditional formatting by field value, or you use a KPI visual.
Task 2: the ranking
Task The meeting starts with the biggest overruns. Create the measure "Rank": the rank of each cost center by [Variance], with the biggest overrun ranked 1.
Actual 535 rows, 5 columns
| EntryID | Date | CostCenterID | AccountID | Amount |
|---|---|---|---|---|
| 1 | 23 Jan 2025 | 300 | 4000 | 88400 |
| 2 | 22 Jan 2025 | 300 | 4000 | 132600 |
| 3 | 12 Jan 2025 | 200 | 5000 | 36176 |
| 4 | 4 Jan 2025 | 600 | 5000 | 5253.5 |
| 5 | 21 Jan 2025 | 100 | 6000 | 13276.2 |
| 6 | 30 Jan 2025 | 100 | 6000 | 9613.8 |
| 7 | 16 Jan 2025 | 200 | 6000 | 49220 |
| 8 | 20 Jan 2025 | 300 | 6000 | 25440 |
| 9 | 29 Jan 2025 | 400 | 6000 | 12875 |
| 10 | 29 Jan 2025 | 500 | 6000 | 17205 |
| 11 | 10 Jan 2025 | 600 | 6000 | 5045.04 |
| 12 | 14 Jan 2025 | 600 | 6000 | 4656.96 |
Showing the first 12 of 535 rows.
Measures: [Total Actual], [Variance]
Budget 432 rows, 4 columns
| Date | CostCenterID | AccountID | Amount |
|---|---|---|---|
| 1 Jan 2025 | 300 | 4000 | 221000 |
| 1 Jan 2025 | 200 | 5000 | 32300 |
| 1 Jan 2025 | 600 | 5000 | 5530 |
| 1 Jan 2025 | 100 | 6000 | 21000 |
| 1 Jan 2025 | 200 | 6000 | 46000 |
| 1 Jan 2025 | 300 | 6000 | 24000 |
| 1 Jan 2025 | 400 | 6000 | 12500 |
| 1 Jan 2025 | 500 | 6000 | 15500 |
| 1 Jan 2025 | 600 | 6000 | 9800 |
| 1 Jan 2025 | 100 | 6300 | 4200 |
| 1 Jan 2025 | 200 | 6300 | 7800 |
| 1 Jan 2025 | 600 | 6300 | 3600 |
Showing the first 12 of 432 rows.
Measures: [Total Budget]
CostCenter 6 rows, 3 columns
| CostCenterID | CostCenter | Division |
|---|---|---|
| 100 | Administration | Administration |
| 200 | Production | Operations |
| 300 | Sales | Sales |
| 400 | Marketing | Sales |
| 500 | IT | Administration |
| 600 | Warehouse | Operations |
Account 7 rows, 4 columns
| AccountID | Account | AccountType | AccountGroup |
|---|---|---|---|
| 4000 | Revenue | Income | Revenue |
| 5000 | Materials | Expense | Materials |
| 6000 | Salaries and Wages | Expense | Personnel |
| 6300 | Rent | Expense | Operating |
| 6500 | Travel | Expense | Operating |
| 6800 | Advertising | Expense | Operating |
| 6900 | Other Expenses | Expense | Operating |
Date 730 rows, 4 columns
| Date | Year | Month | MonthName |
|---|---|---|---|
| 1 Jan 2025 | 2025 | 1 | Jan |
| 2 Jan 2025 | 2025 | 1 | Jan |
| 3 Jan 2025 | 2025 | 1 | Jan |
| 4 Jan 2025 | 2025 | 1 | Jan |
| 5 Jan 2025 | 2025 | 1 | Jan |
| 6 Jan 2025 | 2025 | 1 | Jan |
| 7 Jan 2025 | 2025 | 1 | Jan |
| 8 Jan 2025 | 2025 | 1 | Jan |
| 9 Jan 2025 | 2025 | 1 | Jan |
| 10 Jan 2025 | 2025 | 1 | Jan |
| 11 Jan 2025 | 2025 | 1 | Jan |
| 12 Jan 2025 | 2025 | 1 | Jan |
Showing the first 12 of 730 rows.
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
The first exercise in this lesson is free.
RANKX compares the value of the row with the value of every row of the table in its first argument. With ALL that is every cost center, whichever row is being calculated. More in the lesson on RANKX and TOPN.
Common mistakes
Conditions in the wrong order
SWITCH(TRUE(), [Variance %] > 0.05, "Amber", [Variance %] > 0.1, "Red", "Green") never shows red, because everything above 10% already matches the first condition.
Percentage as a whole number
[Variance %] > 10 is never true, because the measure returns 0.109, not 10.9. Write limits as decimals: 0.1.
RANKX without ALL
RANKX(CostCenter, [Variance]) only sees the one cost center of the row, and every row gets rank 1.
In real Power BI
- Limits change: put them in a small table of their own or a parameter and refer to it in the measure instead of typing them into every formula.
- In the total row RANKX shows rank 1, because all cost centers together compete with the single ones there. With
IF(ISINSCOPE(CostCenter[CostCenter]), RANKX(…))the total row stays empty.
Check your result
- Task 1: Sales is red (10.9%), Production (8.9%) and IT (7.2%) are amber, Administration, Marketing and Warehouse are green. The total row at 6.3% is amber.
- Task 2: Production ranks 1 at 8,293.70 over budget, then Sales, IT, Administration and Warehouse; Marketing, under budget, ranks 6.
Back to case 4 or the course overview.