All DAX Functions

The SWITCH() Function: Replacing Complex Nested IF-ELSE

Clean routing tables instead of nested IF statements.

On this page

Overview

The SWITCH function evaluates an expression against a list of values and returns the result for the first matching value. Combined with TRUE() as the expression, it acts like a readable chain of IF conditions—ideal for bucketing, labeling, and status mapping.

SWITCH(TRUE(), ...) is often cleaner than nested IFs when you have three or more mutually exclusive conditions evaluated in order.

Syntax

DAX Syntax
SWITCH(
    TRUE(),
    <condition1>, <result1>,
    <condition2>, <result2>,
    ...
    [, <else>]
)
  • TRUE(): Forces each condition to be evaluated as a logical test until one matches.
  • Conditions are checked top to bottom; the first TRUE condition wins.
  • Optional final argument is the else/default result when no condition matches.

Example & Dataset

A CustomerReviews table with numeric ratings (1–5):

Sample Data Table: CustomerReviews

ReviewIDCustomerIDRatingComment
R01C105Excellent service
R02C113Average experience
R03C121Very disappointed
R04C134Would recommend
R05C142Below expectations

The DAX Code

Create a calculated column or measure that maps ratings to sentiment labels using SWITCH with TRUE():

Sentiment Label (Calculated Column)
Sentiment Label =
SWITCH(
    TRUE(),
    CustomerReviews[Rating] >= 4, "Positive",
    CustomerReviews[Rating] = 3, "Neutral",
    CustomerReviews[Rating] <= 2, "Negative",
    "Unknown"
)

Expected Output Visual

A table visual with Rating, Comment, and [Sentiment Label]:

Output Table Visual

ReviewIDRatingSentiment Label
R015Positive
R023Neutral
R031Negative
R044Positive
R052Negative

Why Did This Output Happen?

SWITCH evaluates conditions in order. Rating 5 hits the first test (>= 4) → Positive. Rating 3 skips the first, matches the second exactly → Neutral. Ratings 1 and 2 fail the first two tests and match <= 2 → Negative. Rating 4 matches the first condition before later rules run. This pattern keeps sentiment logic readable and easy to extend with new tiers.