OR

OR

How to Use the Power BI DAX function OR

What is the OR function in Power BI DAX?

The OR function in Power BI DAX is a logical function that returns TRUE if at least one of the expressions provided as arguments evaluates to TRUE. If all expressions evaluate to FALSE, the function returns FALSE. The OR function is commonly used in conjunction with other logical functions, such as IF, to create more sophisticated calculations.

Syntax of the OR function

The syntax of the OR function in Power BI DAX is as follows:


OR(condition1, [condition2], ...)


Where:

– `condition1` is the first condition to evaluate.

– `condition2` (optional) is the second condition to evaluate.

– `…` (optional) represents additional conditions to evaluate.

Each condition can be any valid expression that evaluates to TRUE or FALSE. The OR function returns TRUE if at least one of the conditions evaluates to TRUE. Otherwise, it returns FALSE.

Examples of using the OR function

Let’s look at some examples of using the OR function in Power BI DAX.

Example 1: Basic OR function

Suppose we have a table called `Sales` that contains the following columns:

– `OrderID`

– `Product`

– `QuantitySold`

– `PricePerUnit`

We want to create a measure that calculates the total revenue for the products “Product A” or “Product B”. We can use the OR function as follows:


TotalRevenue =

SUMX(

FILTER(

Sales,

OR(

Sales[Product] = "Product A",

Sales[Product] = "Product B"

)

),

Sales[QuantitySold] * Sales[PricePerUnit]

)


In this example, we use the FILTER function to filter the `Sales` table to include only the rows where the product is either “Product A” or “Product B”. We then use the SUMX function to iterate over this filtered table and calculate the total revenue as the sum of `QuantitySold` multiplied by `PricePerUnit`.

Example 2: Using OR with IF function

Suppose we have a table called `Employees` that contains the following columns:

– `EmployeeID`

– `Name`

– `Department`

– `Salary`

We want to create a measure that calculates the total salary for employees in the “Sales” or “Marketing” departments. However, we want to exclude any employees whose salary is less than $50,000. We can use the OR function in combination with the IF function as follows:


TotalSalary =

SUMX(

FILTER(

Employees,

OR(

Employees[Department] = "Sales",

Employees[Department] = "Marketing"

) && Employees[Salary] ❱= 50000

),

Employees[Salary]

)


In this example, we use the FILTER function to filter the `Employees` table to include only the rows where the department is either “Sales” or “Marketing” and the salary is greater than or equal to $50,000. We then use the SUMX function to iterate over this filtered table and calculate the total salary as the sum of the `Salary` column.

The Power BI DAX function OR is a versatile tool that can be used in many different contexts to create more sophisticated measures and calculations. By understanding the syntax and examples of the OR function, users can take advantage of its power to build more dynamic and complex data models in Power BI.

Power BI DAX Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

Subject

Your Name (required)

Company/Organisation

Email (required)

Telephone

Training Course(s)

Your Message

Upload Example Document(s) (Zip multiple files)