Power BI: How to Create Measure with Multiple Filter Conditions


You can use the following syntax in DAX to create a measure that filters rows based on multiple conditions:

Method 1: Create Measure by Filtering with AND Condition

Sum of Points =
CALCULATE (
    SUM ( 'my_data'[Points] ),
    'my_data'[Team] = "A" && 'my_data'[Position] = "Guard"
)

This particular example creates a new measure named Sum of Points that calculates the sum of the values in the Points column only for the rows where the Team column is equal to “A” and the Position column is equal to “Guard.”

Method 2: Create Measure by Filtering with OR Condition

Sum of Points =
CALCULATE (
    SUM ( 'my_data'[Points] ),
    'my_data'[Team] = "A" || 'my_data'[Position] = "Guard"
)

This particular example creates a new measure named Sum of Points that calculates the sum of the values in the Points column only for the rows where the Team column is equal to “A” or the Position column is equal to “Guard.”

The following examples show how to use each method in practice with the following table in Power BI named my_data:

Example 1: Create Measure by Filtering with AND Condition

Suppose we would like to calculate the sum of values in the Points column for the players who are on Team A and have a Position of Guard.

To do so, click the Table tools tab and then click the New measure icon:

Then type the following formula into the formula bar:

Sum of Points =
CALCULATE (
    SUM ( 'my_data'[Points] ),
    'my_data'[Team] = "A" && 'my_data'[Position] = "Guard"
)

We can view this measure by switching to the Report View and inserting a card visualization that displays the value of the measure:

We can see that the sum of points for the players who are on Team A and have a Position of Guard is 36.

Example 2: Create Measure by Filtering with OR Condition

Suppose we would like to calculate the sum of values in the Points column for the players who are on Team A or have a Position of Guard.

To do so, click the Table tools tab and then click the New measure icon:

Then type the following formula into the formula bar:

Sum of Points =
CALCULATE (
    SUM ( 'my_data'[Points] ),
    'my_data'[Team] = "A" || 'my_data'[Position] = "Guard"
)

We can view this measure by switching to the Report View and inserting a card visualization that displays the value of the measure:

We can see that the sum of points for the players who are on Team A or have a Position of Guard is 193.

Additional Resources

The following tutorials explain how to perform other common tasks in Power BI:

How to Count Number of Occurrences in Power BI
How to Write an IF Statement in Power BI
How to Use “If Contains” Formula in Power BI

Leave a Reply

Your email address will not be published. Required fields are marked *