SWITCH

Power BI · Advanced DAX & Time Intelligence

Theory

SWITCH(expression, value1, result1, value2, result2, ..., else) evaluates an expression and returns the result for the first matching value, or the optional else result if nothing matches. It replaces long chains of nested IF statements and is far easier to read. A simple use maps codes to labels, for example SWITCH(SELECTEDVALUE(Sales[Region]), "North", "N", "West", "W", "Other").

The most popular pattern is SWITCH(TRUE(), condition1, result1, condition2, result2, ..., else): because the expression is TRUE, the first condition that is true wins, so you can test ranges. A Customer Tier measure with [Total Sales] >= 2500 → "Gold", >= 1000 → "Silver", else "Bronze" gives Asha Gold (₹2,700), Ravi Silver (₹2,400), and Meera (₹600) and Karan (₹500) Bronze. Conditions are checked in order, so put the strictest first. SWITCH is also used for dynamic measure selection and conditional-format colours.

Why we use it

Business rules often have several branches: tiers, bands, status labels. SWITCH expresses them clearly and keeps the logic in one maintainable place.

When to use it

Use SWITCH whenever you have more than two branches. Use IF for a single condition. When the bands must be used on slicers or axes, put the same logic in a calculated column or Power Query instead of a measure.

How it works

  1. Evaluate Customer Tier for a customer
  2. Is Total Sales >= 2500? Yes: Return Gold. No: Check the next condition.
  3. Is Total Sales >= 1000? Yes: Return Silver. No: Return the else value Bronze.
  4. Tier shown in the visual

Syntax

SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])
SWITCH(TRUE(), <condition1>, <result1>, <condition2>, <result2>, <else>)

Example

Customer Tier = 
SWITCH(
    TRUE(),
    [Total Sales] >= 2500, "Gold",
    [Total Sales] >= 1000, "Silver",
    "Bronze"
)

Region Code = SWITCH(SELECTEDVALUE(Sales[Region]), "North", "N", "West", "W", "South", "S", "All")

Key points

Power BI topics

Power BI Introduction

Getting Data

Power Query (Data Transformation)

Data Modeling

DAX (Data Analysis Expressions)

Data Visualization

Dashboards & Reports

Power BI Service

Advanced Features

Projects & Case Studies

Interview & Certification

Advanced DAX & Time Intelligence

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Power BI Dashboards & DAX

Learn data visualization and interactive dashboards step-by-step. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice DAX Online 250 business scenarios on a star schema — write a measure and compare your visual with the expected one. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Power BI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax / Where to find it
{{ current.syntax }}
Example
{{ current.example }}
What You'll Learn — click to check off
  • {{ pt.mark }} {{ pt.text }}

Share this topic