Stop Hard-Coding Power BI Categories in DAX

Every Power BI developer has written this column. You build something that sorts your data into neat categories, it works first time, you feel quietly pleased with yourself. Then a month later the business adds a category or renames one, and you’re back in the formula doing surgery. A month after that, again.
The DAX isn’t the problem. The problem is that the logic was welded to one exact version of reality, and reality moved. Here’s how to build classification that bends when the business changes its mind, instead of snapping.
The fragile version we’ve all shipped
Most classification columns start life looking like this:
Category =
IF('Data'[Type] = "Premium", "Tier 1",
IF('Data'[Type] = "Standard", "Tier 2",
"Tier 3"))
It works. But every new type means another nested IF, the indentation marches off to the right, and there’s nothing handling blanks or anything unexpected. Fine until it isn’t.
Step 1: Move to SWITCH(TRUE())
First, swap the nested IFs for SWITCH(TRUE()). It reads top to bottom like a list of rules, and adding one doesn’t mean re-nesting the lot:
Category =
VAR vType = 'Data'[Type]
RETURN
SWITCH(TRUE(),
vType = "Premium", "Tier 1",
vType = "Standard", "Tier 2",
"Tier 3"
)
Cleaner. But it’s still one value per line, which is the next thing to deal with.
Step 2: Match against lists, not single values
In real life, several values usually belong to the same group. Rather than a branch per value, define a list and check membership with CONTAINSROW():
Category =
VAR vType = 'Data'[Type]
VAR vTier1 = {"Premium", "Enterprise", "Platinum"}
VAR vTier2 = {"Standard", "Business", "Pro"}
RETURN
SWITCH(TRUE(),
CONTAINSROW(vTier1, vType), "Tier 1",
CONTAINSROW(vTier2, vType), "Tier 2",
"Tier 3"
)
When “Platinum Plus” turns up next quarter, you drop it into the vTier1 list and you’re done. No structural change, no redeploy panic.
Step 3: Plan for blanks and the unexpected
Production data is messy. That’s not pessimism, it’s just what happens. Handle blanks explicitly (unhandled blanks are one of the silent DAX mistakes), and always keep a catch-all on the end so nothing slips through:
Category =
VAR vType = 'Data'[Type]
VAR vTier1 = {"Premium", "Enterprise", "Platinum"}
VAR vTier2 = {"Standard", "Business", "Pro"}
RETURN
SWITCH(TRUE(),
ISBLANK(vType), "Uncategorised", -- blanks first
CONTAINSROW(vTier1, vType), "Tier 1",
CONTAINSROW(vTier2, vType), "Tier 2",
"Tier 3" -- everything else lands here
)
Now the column copes with blanks, groups values cleanly, and never leaves a row sitting there unclassified. If you build this as a measure instead, for a matrix or a card, swap in SELECTEDVALUE('Data'[Type]).
Step 4: Add a second condition
Sometimes a category depends on two things, a type and a status, say. The pattern stretches to fit without getting ugly:
Category =
VAR vType = 'Data'[Type]
VAR vStatus = 'Data'[Status]
VAR vTier1 = {"Premium", "Enterprise"}
RETURN
SWITCH(TRUE(),
ISBLANK(vStatus) || vStatus = "Inactive", "Dormant",
CONTAINSROW(vTier1, vType), "Tier 1",
"Standard"
)
Every rule is still its own line, so it stays readable however many conditions you stack up.
Why bother
The payoff is maintenance. When the change request lands, and it always lands, you’re editing a list, not rebuilding a formula. Five seconds instead of a debugging session followed by a redeploy.
The principle worth keeping is to separate your rules from your structure. Put the bits that change (the category lists) somewhere obvious and easy to edit, and leave the logic that processes them alone. Your future self, opening this column eight months from now with no memory of writing it, will be grateful.