How to Compare Two Columns in Power BI (With Example)


You can use the following syntax in DAX to create a new column that checks if the values in two columns are equal or not:

Equal = IF('my_data'[Game 1] = 'my_data'[Game 2], "Yes", "No")

This particular example creates a new column named Equal that returns “Yes” if the values in the Game 1 and Game 2 columns are equal or “No” otherwise.

The following example shows how to use this syntax in practice.

Example: How to Compare Two Columns in Power BI

Suppose we have the following table in Power BI named my_data that contains information about points scored by various basketball players in two different games:

Suppose we would like to add a new column that checks if the values in the Game 1 and Game 2 columns are equal in each row.

To do so, click the Table tools tab along the top ribbon, then click the New column icon:

Then type in the following formula into the formula bar:

Equal = IF('my_data'[Game 1] = 'my_data'[Game 2], "Yes", "No")

This will create a new column named Equal that contains either “Yes” or “No” to indicate if the values in the Game 1 and Game 2 columns are equal:

Power BI compare two columns

From the output we can see:

  • The first player had equal values in the Game 1 and Game 2 columns.
  • The second player did not have equal values in the Game 1 and Game 2 columns.
  • The third player did not have equal values in the Game 1 and Game 2 columns.

And so on.

Note that we could also return numeric values instead of strings if we’d like.

For example, we can use the following syntax to return 1 if two columns have the same value or 0 otherwise:

Equal = IF('my_data'[Game 1] = 'my_data'[Game 2], 1, 0)

This will create a new column named Equal that contains either 1 or 0 to indicate if the values in the Game 1 and Game 2 columns are equal:

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 Use “If Contains” in Power BI
How to Write an IF Statement in Power BI

Featured Posts

Leave a Reply

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