Traffic-light status: nested IF vs SWITCH(TRUE())

Label months Green, Amber or Red against a benchmark with a nested IF, and see how SWITCH(TRUE()) writes the same logic more readably.

You will learn to

  • Write three outcomes with an IF inside an IF
  • Rewrite a nested IF as SWITCH(TRUE(), …)
  • Order tests so each value lands in the right band

How it works

A traffic light needs three outcomes, and IF only has two. The classic fix is to put a second IF in the “otherwise” slot of the first:

`IF(test 1, result 1, IF(test 2, result 2, result 3))`

DAX checks test 1; only when it fails does it move on to the inner IF. `SWITCH(TRUE(), test 1, result 1, test 2, result 2, result 3)` does exactly the same thing and stays flat however many bands you add, so most people switch to it beyond three outcomes. You will meet both in real reports.

In either form, **order matters**: put the strictest test first. A month at 120% of the benchmark also passes “at least 90%”, so that test must come second.

Practice it hands-on with a real data model and a live report that updates as you type.

Activity = IF([Total Sales] >= 20000, "Busy", IF([Total Sales] >= 10000, "Normal", "Quiet"))