Home|Blog|IF, SWITCH, and DIVIDE: The DAX Logic Essentials
Sign in →
power-bi
dax
logic
measures

IF, SWITCH, and DIVIDE: The DAX Logic Essentials

By Shashikant·18 July 2026·4 min read

IF, SWITCH, and DIVIDE: The DAX Logic Essentials

Most of the conditional logic you'll ever write in Power BI comes down to three DAX functions: IF, SWITCH, and DIVIDE. Get comfortable with these and you can express almost any business rule cleanly. Use them badly, with nested IFs ten levels deep or raw division operators, and your measures become unreadable and error-prone. This guide walks Indian data analysts through each one with practical examples.

IF: Simple Two-Way Branching

IF is the workhorse for a single condition. It takes a test, a result if true, and an optional result if false.

Order Status =
IF (
    Sales[Amount] >= 1000,
    "Free Delivery",
    "Add ₹" & ( 1000 - Sales[Amount] ) & " more"
)

If the order crosses ₹1,000, the customer gets free delivery; otherwise we tell them how much more to add. The third argument is optional, but always provide it. If you omit it, a false result returns BLANK, which can produce confusing visuals.

Nested IF: Where It Goes Wrong

The trouble starts when you have more than two outcomes and stack IFs inside IFs.

-- Hard to read, easy to break
Performance =
IF (
    [Total Sales] >= 100000, "Excellent",
    IF (
        [Total Sales] >= 50000, "Good",
        IF ( [Total Sales] >= 20000, "Average", "Poor" )
    )
)

This works, but it's painful to read and edit. There's a much cleaner way.

SWITCH: Clean Multi-Condition Logic

SWITCH evaluates one expression against a list of values and returns the matching result. It replaces a chain of IFs when you're comparing against fixed values.

Region Name =
SWITCH (
    Sales[RegionCode],
    "N", "North",
    "S", "South",
    "E", "East",
    "W", "West",
    "Unknown"   -- default / else
)

The last argument with no preceding value is the default, returned when nothing matches. This is far cleaner than four nested IFs comparing the same column.

The SWITCH TRUE Pattern

The real superpower is SWITCH ( TRUE (), ... ). By switching on TRUE(), each branch can be its own logical condition, not just an equality check. This is the idiomatic replacement for nested IFs.

Performance =
SWITCH (
    TRUE (),
    [Total Sales] >= 100000, "Excellent",
    [Total Sales] >= 50000, "Good",
    [Total Sales] >= 20000, "Average",
    "Poor"
)

Read it top to bottom: the first condition that evaluates to TRUE wins. This is dramatically easier to read and maintain than the nested IF version, and adding a new tier is a one-line change.

Order matters. SWITCH TRUE stops at the first match, so put your conditions in the right sequence. If you reversed the order above and checked >= 20000 first, everything above ₹20,000 would be tagged "Average".

A common Indian retail use is bucketing customers for a loyalty tier:

Loyalty Tier =
SWITCH (
    TRUE (),
    [Lifetime Spend] >= 50000, "Platinum",
    [Lifetime Spend] >= 20000, "Gold",
    [Lifetime Spend] >= 5000, "Silver",
    "Bronze"
)

DIVIDE: Safe Division Every Time

Never write [A] / [B] in DAX. If [B] is zero or blank, you get an Infinity or error that breaks visuals. DIVIDE handles this gracefully.

Conversion Rate =
DIVIDE (
    [Total Orders],
    [Total Visitors],
    0   -- optional: value returned when denominator is 0 or blank
)

The third argument is what to return on a zero/blank denominator. If you omit it, DIVIDE returns BLANK instead of erroring, which is usually what you want.

Consider a Swiggy restaurant dashboard computing average order value where some restaurants had zero orders today:

Avg Order Value =
DIVIDE ( [Total Revenue], [Total Orders] )

With the / operator this would error for any restaurant with no orders. DIVIDE quietly returns blank, keeping your matrix clean.

Combining All Three

Real measures often use them together. Here's a measure that classifies month-over-month growth for a Flipkart category.

Growth Tier =
VAR CurrentSales = [Total Sales]
VAR PreviousSales =
    CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )
VAR GrowthPct = DIVIDE ( CurrentSales - PreviousSales, PreviousSales )
RETURN
    SWITCH (
        TRUE (),
        ISBLANK ( PreviousSales ), "New",
        GrowthPct > 0.1, "High Growth",
        GrowthPct > 0, "Growing",
        GrowthPct = 0, "Flat",
        "Declining"
    )

DIVIDE protects the percentage, variables keep it readable, and SWITCH TRUE handles the five outcomes cleanly.

Best Practices and Pitfalls

  • Use SWITCH instead of 3+ nested IFs. Once you have three or more branches, switch to SWITCH.
  • Always order SWITCH TRUE conditions carefully. First match wins.
  • Always use DIVIDE, never /. Even if you "know" the denominator can't be zero today, data changes.
  • Provide the false/default argument. Don't rely on accidental BLANKs.
  • Watch data types in IF. Both result branches should return the same type; mixing text and numbers causes errors or unexpected blanks.
  • Avoid heavy expressions repeated in each branch. Compute them once in a VAR first.

Conclusion

IF, SWITCH, and DIVIDE cover the vast majority of conditional logic in Power BI. Reach for IF when there are two outcomes, graduate to SWITCH TRUE the moment you have more, and wrap every division in DIVIDE to stay error-free. These three functions, used well, will make your measures readable and bulletproof, exactly the standard Indian data teams expect.

Related: What is DAX and Why It Matters · Practice Power BI

Don't just read. Prove your skill on DevWithData.

DevWithData

Shashikant

· Founder, DevWithData

Data professional and Power BI instructor. Building DevWithData to help analysts prove their skills, not just collect certificates.

Reading is not enough. Prove your skill.

DevWithData measures your actual ability with the Data Readiness Index. Stop reading — start practicing.

Continue Learning