Learn how to use DAX logical functions — IF, AND, OR, and IN — to encode real business rules directly into your Power BI measures and calculated columns. This hands-on lesson walks through realistic sales scenarios, common pitfalls, and patterns you'll use in almost every project.

Imagine you're building a sales dashboard for a retail company. Your manager wants a column that flags whether a transaction qualifies for a bonus commission — but the rule isn't simple. The rep must have sold over $5,000 in a single order, the product must be in a premium category, and it can't be a discounted sale. That's three conditions working together, and none of Power BI's basic aggregation functions can express that kind of logic on their own.
This is exactly where DAX logical functions earn their keep. Functions like IF, AND, OR, and IN let you encode business rules directly into your measures and calculated columns — turning plain numbers into answers to real questions. Instead of exporting to Excel to apply conditional formatting or doing manual analysis, you build the intelligence into the data model itself.
By the end of this lesson, you'll be able to write conditional DAX expressions that handle multi-layered business rules with confidence. You'll understand not just the syntax of each function, but why they work the way they do — including some surprising quirks that trip up beginners.
What you'll learn:
IF works as the fundamental building block of conditional logic in DAXAND and OR (and their shorthand operators)INThis lesson assumes you're comfortable opening Power BI Desktop and working in the DAX formula bar. You should understand the difference between a measure and a calculated column — if you're fuzzy on that distinction, read DAX Fundamentals: When to Use Calculated Columns vs Measures in Power BI before continuing. You don't need to know anything about filter context yet, though it will come up briefly.
A logical function is any function that evaluates a condition and returns a result based on whether that condition is TRUE or FALSE. In everyday language, you do this constantly: "If it's raining, take an umbrella. Otherwise, don't." In DAX, you're expressing that same kind of reasoning about your data.
Logical functions are powerful because they let you make your reports responsive to meaning, not just numbers. Instead of showing raw revenue figures, you can show whether a sales rep hit their target. Instead of listing transaction amounts, you can categorize them as Low, Medium, or High value. The measure becomes an answer, not just a number.
DAX logical functions also behave differently from what you might expect if you're coming from Excel formulas — particularly around how they handle context. We'll call out those differences as we go.
IF is the most fundamental logical function in DAX. Its job is simple: evaluate a condition, return one value if it's TRUE, and return a different value if it's FALSE.
Syntax:
IF(<logical_test>, <value_if_true>, <value_if_false>)
The third argument — value_if_false — is optional. If you leave it out, DAX returns BLANK when the condition is FALSE.
Suppose you have a Sales table with an OrderAmount column. You want a measure that labels each context as "High Value" or "Standard":
Order Category =
IF(
SUM(Sales[OrderAmount]) > 5000,
"High Value",
"Standard"
)
Here, SUM(Sales[OrderAmount]) > 5000 is the logical test. It evaluates to either TRUE or FALSE, and IF returns the appropriate text value.
Note
When you write this as a measure, the SUM aggregates all rows in the current filter context — for example, all orders for a specific sales rep in a specific month. When you write it as a calculated column, each row is evaluated individually. This distinction matters a lot once your conditions get complex.
IF can return any data type — text, numbers, booleans, even BLANK. Here's a measure that returns a numeric bonus amount:
Bonus Amount =
IF(
SUM(Sales[OrderAmount]) >= 10000,
SUM(Sales[OrderAmount]) * 0.05,
0
)
Reps who sell $10,000 or more get a 5% bonus; everyone else gets zero. Notice that both the TRUE and FALSE branches return numbers, which keeps the measure usable in charts and aggregations.
Tip
Always make both branches of your IF return the same data type. If the TRUE branch returns a number and the FALSE branch returns text, Power BI will coerce types in unpredictable ways, and you'll get unexpected results in visuals.
Most real business rules involve more than one condition. DAX gives you two ways to combine conditions: the AND and OR functions, and their shorthand operators (&& and ||).
AND returns TRUE only when every condition you give it is TRUE. Think of it as the strictest possible gate.
Function syntax:
AND(<logical1>, <logical2>)
Operator syntax (preferred for readability):
<logical1> && <logical2>
Warning
The DAX AND function only accepts exactly two arguments. If you have three conditions, you have to nest: AND(condition1, AND(condition2, condition3)). This gets ugly fast. For three or more conditions, use the && operator instead — it scales naturally: condition1 && condition2 && condition3.
Here's a measure that checks whether a sale meets bonus criteria — the order must exceed $5,000 AND the customer must be classified as "Enterprise":
Qualifies for Bonus =
IF(
SUM(Sales[OrderAmount]) > 5000
&& MAX(Sales[CustomerTier]) = "Enterprise",
"Eligible",
"Not Eligible"
)
We use MAX on CustomerTier here because in a measure context, we need an aggregation. If you're writing a calculated column, you'd reference the column directly: Sales[CustomerTier] = "Enterprise".
OR returns TRUE when any of the conditions is TRUE. It's more permissive than AND.
Function syntax:
OR(<logical1>, <logical2>)
Operator syntax:
<logical1> || <logical2>
The same nesting limitation applies to the OR function — it only accepts two arguments. Use || for three or more conditions.
Here's a measure that flags a sale as "Priority" if the order is large OR the customer is in a preferred region:
Priority Sale =
IF(
SUM(Sales[OrderAmount]) > 8000
|| MAX(Sales[Region]) = "Northeast",
"Priority",
"Standard"
)
Real business logic often mixes both. This is where parentheses become critical — they control the order of evaluation, just like in math.
Consider this rule: A transaction qualifies for a special discount if the product is in the "Electronics" or "Software" category AND the order amount exceeds $3,000.
Special Discount Eligible =
IF(
(
MAX(Sales[Category]) = "Electronics"
|| MAX(Sales[Category]) = "Software"
)
&& SUM(Sales[OrderAmount]) > 3000,
"Eligible",
"Not Eligible"
)
The parentheses around the OR expression are essential. Without them, DAX would evaluate "Software" AND SUM(Sales[OrderAmount]) > 3000 first, which is not what you want. When you mix AND and OR, always use parentheses to make your intent explicit.
Key insight
Think of AND/OR combinations like spoken language. "Electronics or Software, and over $3,000" — the comma after "Software" is your parenthesis. Group the OR clause first, then apply the AND condition to the whole group.
One pattern that comes up constantly in business reporting is "does this value belong to a specific list?" You might need to check whether a region is one of several key markets, whether a product code is in a list of flagged SKUs, or whether a customer falls into one of several VIP tiers.
You could write this with chained OR statements:
-- Verbose and hard to maintain
Is Key Market =
IF(
MAX(Sales[Region]) = "Northeast"
|| MAX(Sales[Region]) = "West Coast"
|| MAX(Sales[Region]) = "Midwest",
"Key Market",
"Other"
)
But DAX gives you a much cleaner tool: the IN operator.
Syntax:
<expression> IN { <value1>, <value2>, <value3>, ... }
The curly braces create an inline table of values. IN returns TRUE if the expression matches any value in that table.
Here's the same logic, rewritten with IN:
Is Key Market =
IF(
MAX(Sales[Region]) IN { "Northeast", "West Coast", "Midwest" },
"Key Market",
"Other"
)
This is dramatically easier to read and maintain. When a fourth region gets added to the key markets list, you add one item to the curly braces rather than appending another || clause.
IN works equally well with numeric values:
Flagged Product =
IF(
MAX(Sales[ProductCode]) IN { 1042, 1087, 1103, 2201 },
"Flagged",
"Clear"
)
Tip
IN is case-sensitive for text comparisons by default in some configurations. If you're matching text and getting unexpected FALSE results, double-check that your capitalization matches the actual data values exactly.
Sometimes a binary TRUE/FALSE isn't enough — you need to categorize into three, four, or more buckets. The classic approach is to nest IF statements.
Example: Categorize transactions by value tier.
Order Value Tier =
IF(
SUM(Sales[OrderAmount]) >= 10000,
"Platinum",
IF(
SUM(Sales[OrderAmount]) >= 5000,
"Gold",
IF(
SUM(Sales[OrderAmount]) >= 1000,
"Silver",
"Bronze"
)
)
)
This works, but it gets hard to read as you add more levels. DAX evaluates these from the outside in — the first condition is checked first, and if it's TRUE, the inner IFs never run. That's actually a performance feature: once a match is found, evaluation stops.
Warning
Deeply nested IFs (more than 3-4 levels) become a maintenance nightmare. If you find yourself writing more than three nested IFs, consider switching to SWITCH with a TRUE() pattern, which is cleaner and easier to extend. You can learn more about that approach in Advanced DAX Patterns: Variables, SWITCH, and Iterator Functions.
Let's build something genuinely useful. You're a Power BI developer for a software company. The sales team has asked for a measure that assigns each deal a "Commission Tier" based on these rules:
Here's how you'd build this step by step.
First, define the conditions clearly:
Commission Tier =
VAR DealValue = SUM(Sales[DealAmount])
VAR CustomerSegment = MAX(Sales[Segment])
VAR IsStrategicCustomer =
CustomerSegment IN { "Enterprise", "Mid-Market" }
RETURN
IF(
DealValue > 20000 && IsStrategicCustomer,
"Tier A",
IF(
DealValue >= 5000 || IsStrategicCustomer,
"Tier B",
"Tier C"
)
)
Notice how using variables (VAR) makes this dramatically easier to read. Each piece of logic has a name. The RETURN section reads almost like English. This is a pattern you should adopt as soon as you feel comfortable with the basics — you can explore it further in DAX Variables in Practice: Using VAR and RETURN to Simplify Complex Measures.
Build this in Power BI Desktop using the following scenario. If you don't have your own dataset handy, create a simple table using Enter Data (Home tab → Enter data) with these columns: SalesRep, Region, ProductCategory, OrderAmount.
Add a few rows with varied values:
Exercise tasks:
Write a measure called Order Flag that returns "High Value" if OrderAmount is over $5,000, and "Standard" otherwise.
Write a measure called Priority Region that returns "Priority" if the region is "Northeast" OR "West Coast", and "Standard" for all other regions.
Write a measure called Bonus Eligible that returns "Yes" if the order exceeds $3,000 AND the product category is in { "Software", "Hardware" }, and "No" otherwise.
Combine all three rules into a single measure called Deal Score that returns:
For task 4, you'll need to calculate how many conditions are TRUE. Consider using a variable like:
VAR ConditionCount =
IF([Order Flag] = "High Value", 1, 0)
+ IF([Priority Region] = "Priority", 1, 0)
+ IF([Bonus Eligible] = "Yes", 1, 0)
Then use IF with that count. This is a useful pattern for scoring logic that you'll return to again and again.
-- This might fail silently if data is "enterprise" not "Enterprise"
IF(MAX(Sales[Segment]) = "Enterprise", ...)
Always check your actual data values. Use a simple table visual to see exact values before writing conditions.
-- This will throw an error
IF(AND(condition1, condition2, condition3), ...)
-- Use && instead
IF(condition1 && condition2 && condition3, ...)
-- Problematic: TRUE branch returns number, FALSE branch returns text
IF(SUM(Sales[Amount]) > 1000, SUM(Sales[Amount]), "No Sales")
This will cause type conflicts in visuals. Decide: do you want a number or a label? If a label, return text from both branches. If a number, return 0 or BLANK() from the false branch.
A very common trap for beginners is writing something like:
-- This does NOT filter the data; it just labels the total
Enterprise Sales =
IF(
MAX(Sales[Segment]) = "Enterprise",
SUM(Sales[Amount]),
0
)
This measure checks whether the current context is Enterprise — it doesn't sum only Enterprise rows. If you want to sum a subset of rows, you need CALCULATE with a filter. Understanding this distinction is core to DAX mastery, and Understanding DAX: CALCULATE and Filter Context will give you the full picture.
Key insight
IF in a measure asks "what does the current context look like?" It doesn't filter rows within a table. For row-level filtering inside an aggregation, CALCULATE with a filter argument is the right tool.
-- What does this actually evaluate?
condition1 || condition2 && condition3
DAX gives && higher precedence than ||, similar to how multiplication takes precedence over addition. This means DAX reads the above as condition1 || (condition2 && condition3), which may not be what you intended. When in doubt, use parentheses.
You've now covered the core toolkit for conditional logic in DAX. Here's what you built:
IF evaluates a single condition and returns different values for TRUE and FALSEAND / && requires all conditions to be TRUE; use && for more than two conditionsOR / || requires at least one condition to be TRUE; use || for more than two conditionsIN tests whether a value belongs to a list — cleaner than chaining OR statementsVAR/RETURN) make complex conditional logic readable and debuggableThese functions are the building blocks you'll use in almost every real-world Power BI project. Once you're comfortable with them, the natural next step is understanding how the data context around your measure affects what your conditions evaluate to. That's the domain of filter context, and Row Context vs Filter Context: The Mental Model Every DAX User Needs will give you that foundation.
From there, you'll want to look at how to build richer segmentation logic — turning these conditional flags into dynamic customer groupings and analytics — which is covered in depth in Dynamic Segmentation and Grouping with DAX: Build Flexible Customer Analytics.
Finally, if you're using these logical patterns inside calculated columns that also need to handle errors from blank values or division, make sure to read DAX Error Handling in Practice: Using IFERROR, ISBLANK, and DIVIDE to Build Robust Measures — because robust measures handle edge cases gracefully, not by accident.