Daily DAX : DAy 377 OR
Power BI DAX: OR() Function
Overview
The OR() function in DAX (Data Analysis Expressions) is a logical function that evaluates two expressions and returns TRUE if either of them is true.
Syntax
OR(<expression1>, <expression2>)
- <expression1>: First logical expression to evaluate
- <expression2>: Second logical expression to evaluate
Returns: TRUE if either expression is true; otherwise FALSE.
How It Works
Truth Table:
| Expression 1 | Expression 2 | OR Result |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
Use Cases
1. Conditional Calculations
Scenario: Flag sales as "High Value" if amount > 1000 or quantity > 50.
High Value Sale =
IF(
OR(
Sales[Amount] > 1000,
Sales[Quantity] > 50
),
"Yes",
"No"
)
2. Filtering in Measures
Scenario: Count customers from USA or Canada.
US or Canada Customers =
CALCULATE(
COUNTROWS(Customers),
OR(
Customers[Country] = "USA",
Customers[Country] = "Canada"
)
)
3. Row Context in Calculated Columns
Scenario: Categorize products as "Priority" if discontinued or low stock.
Priority Product =
IF(
OR(
Products[Discontinued] = TRUE(),
Products[Stock] < 10
),
"Priority",
"Standard"
)
Alternative: Using || Operator
DAX allows using the || operator as a shorter alternative:
OR(Sales[Amount] > 1000, Sales[Quantity] > 50)
-- is equivalent to --
Sales[Amount] > 1000 || Sales[Quantity] > 50
Recommendation: Use || for cleaner, more readable code.
Best Practices
- Use
||instead ofOR()for better readability - Avoid nesting too many
ORconditions — considerIN()orSWITCH() - Use in
FILTER(),CALCULATE(), or calculated columns as needed
Better with IN():
OR(Customers[Country] = "USA", Customers[Country] = "Canada")
-- Better as --
Customers[Country] IN { "USA", "Canada" }
Comments
Post a Comment