Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

3.3 Logical Functions: IF, SWITCH, AND, OR

Lesson 24 of 62 in the free Power BI notes on Siksha Sarovar, written by Rohit Jangra.

DAX Logical Functions

Logical functions evaluate conditions and return results based on whether conditions are true or false. They are essential for implementing business logic in Power BI.

IF()

Evaluates a condition and returns one value if true, another if false.

Syntax: IF(Condition, ValueIfTrue, ValueIfFalse)

Examples:

Status = IF(Sales[Amount] > 1000, "High", "Low")
Profit Status = IF([Total Profit] > 0, "Profit", "Loss")

Nested IF:

Grade =
IF(Sales[Score] >= 90, "A",
IF(Sales[Score] >= 80, "B",
IF(Sales[Score] >= 70, "C", "D")))

Tip: For multiple conditions, prefer SWITCH() over nested IF() for readability.

SWITCH()

Evaluates an expression against a list of values and returns the corresponding result. Cleaner alternative to nested IF statements.

Syntax: SWITCH(Expression, Value1, Result1, Value2, Result2, ..., DefaultResult)

Examples:

Day Name =
SWITCH(
    Dates[DayNumber],
    1, "Monday",
    2, "Tuesday",
    3, "Wednesday",
    4, "Thursday",
    5, "Friday",
    6, "Saturday",
    7, "Sunday",
    "Unknown"
)

SWITCH with TRUE() — for conditions:

Sales Category =
SWITCH(
    TRUE(),
    [Total Sales] > 100000, "Platinum",
    [Total Sales] > 50000, "Gold",
    [Total Sales] > 10000, "Silver",
    "Bronze"
)

AND() and OR()

FunctionDescriptionReturns TRUE when
AND()Logical ANDBoth conditions are true
OR()Logical ORAt least one condition is true
NOT()Logical NOTThe condition is false

Syntax: AND(Condition1, Condition2) OR(Condition1, Condition2)

Using Operators (Alternative Syntax):

Eligible = IF(Sales[Age] >= 18 && Sales[Status] = "Active", "Yes", "No")

&& is equivalent to AND()|| is equivalent to OR()

Examples:

VIP Customer =
IF(
    AND(Customers[TotalSpend] > 50000, Customers[Years] > 3),
    "VIP",
    "Regular"
)
Needs Attention =
IF(
    OR([Sales] < 1000, [Returns] > 100),
    "Review",
    "OK"
)

Comparison: IF vs SWITCH

FeatureIF()SWITCH()
Best ForSimple true/false conditionsMultiple discrete values
ReadabilityGets messy with nestingClean with many options
PerformanceSlightly faster for 1-2 conditionsBetter for 3+ conditions
FlexibilityCan use any expressionMatches exact values (or TRUE() pattern)