← Back to Chapters

IF & SWITCH Functions in DAX

? IF & SWITCH Functions in DAX

✨ Quick Overview

IF and SWITCH are decision-making functions in DAX. They help convert raw numbers into meaningful business labels such as Pass/Fail, Grade, Status, or Category.

? Key Concepts

  • Both functions work row by row
  • Mostly used in Calculated Columns
  • IF = simple condition
  • SWITCH = multiple conditions

? Syntax / Theory

? IF Syntax
// Basic IF syntax
IF(Condition,Result_if_True,Result_if_False)
? SWITCH Syntax
// SWITCH with TRUE for range conditions
SWITCH(
TRUE(),
Condition1,Result1,
Condition2,Result2,
DefaultResult
)

? Common Path for ALL Examples

  1. Open Power BI Desktop
  2. Home → Enter Data → Load table
  3. Go to Data View
  4. Modeling → New Column
  5. Write DAX formula

? Sample Data – Students

ID Name Marks
1 Aditi 92
2 Rahul 76
3 Neha 61
4 Aman 35

✅ Example 1: IF – Pass / Fail

Business Question: Has the student passed?
Rule: Marks ≥ 40 → Pass else Fail

? View Code Example
// Pass or Fail decision for each student
Result =
IF(Students[Marks] >= 40,"Pass","Fail")
Aditi → Pass
Rahul → Pass
Neha → Pass
Aman → Fail
 

✅ Example 2: IF – Scholarship Eligibility

Business Question: Who gets scholarship?
Rule: Marks ≥ 80 → Eligible else Not Eligible

? View Code Example
// Scholarship eligibility logic
Scholarship =
IF(Students[Marks] >= 80,"Eligible","Not Eligible")
 

✅ Example 3: SWITCH – Student Grade

? View Code Example
// Grade assignment using SWITCH
Grade =
SWITCH(
TRUE(),
Students[Marks] >= 90,"A",
Students[Marks] >= 75,"B",
Students[Marks] >= 60,"C",
"D"
)
 

? Use Cases

  • Pass / Fail logic
  • Grades and ratings
  • Status flags
  • Business classifications

⚡ DAX Logic Simulator

Enter a numeric value below to see how all three DAX functions would process it simultaneously.

IF (Pass/Fail) -
Nested IF (Scholar) -
SWITCH (Grade) -

? Tips & Best Practices

  • Use IF for simple conditions
  • Use SWITCH for multiple ranges
  • Keep conditions ordered correctly
  • Prefer calculated columns for labels

? Try It Yourself

  • Create Salary Band using SWITCH
  • Create Age Category column
  • Create Performance Rating