How to Select Rows Based on Condition in Power BI


You can use one of the following methods to select rows based on condition in Power BI:

Method 1: Select Rows Based on One Condition

filtered_data =
CALCULATETABLE('my_data', 'my_data'[Team] = "A")

Method 2: Select Rows Based on Multiple Conditions

filtered_data =
CALCULATETABLE('my_data', 'my_data'[Team] = "A" && 'my_data'[Points] > 20)

Method 3: Select Rows Based on Value in List

filtered_data =
CALCULATETABLE('my_data', 'my_data'[Team] IN {"A", "C"})

The following examples show how to use each method in practice with the following table in Power BI that contains information about various basketball players:

Example 1: Select Rows Based on One Condition

Suppose that we would like to select only the rows from my_table where the value in the Team column is equal to A.

To do so, click the Table tools tab and then click New table and then type the following formula into the formula bar:

filtered_data =
CALCULATETABLE('my_data', 'my_data'[Team] = "A")

This will create a new table that only contains the rows from the original table where the value in the Team column is equal to A:

Power BI select rows based on condition

Example 2: Select Rows Based on Multiple Conditions

Suppose that we would like to select only the rows from my_table where the value in the Team column is equal to A and the value in the Points column is greater than 20.

To do so, click the Table tools tab and then click New table and then type the following formula into the formula bar:

filtered_data =
CALCULATETABLE('my_data', 'my_data'[Team] = "A" && 'my_data'[Points] > 20)

This will create a new table that only contains the rows from the original table where the value in the Team column is equal to A and the value in the Points column is greater than 20:

Power BI select rows based on multiple conditions

Example 3: Select Rows Based on Value in List

Suppose that we would like to select only the rows from my_table where the value in the Team column is equal to A or C.

To do so, click the Table tools tab and then click New table and then type the following formula into the formula bar:

filtered_data =
CALCULATETABLE('my_data', 'my_data'[Team] IN {"A", "C"})

This will create a new table that only contains the rows from the original table where the value in the Team column is equal to A or C:

Note: In this example we only included two values in the list between the curly brackets, but you can include as many values as you’d like.

Additional Resources

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

A Simple Formula for “If Contains” in Power BI
How to Write an IF Statement in Power BI
How to Write an IF Statement with Multiple Conditions in Power BI

Leave a Reply

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