Can someone explain how to compare two columns in Power BI, using an example?

Power BI is a powerful data analysis tool that allows users to compare data from different columns in a single visual. To compare two columns in Power BI, you can use the “Add Column” feature to create a calculated column that compares the values in the two columns. For example, if you have a sales data set with two columns for “Revenue” and “Expenses,” you can create a new column that calculates the net profit by subtracting the expenses from the revenue. This will allow you to easily compare the profitability of different products or time periods. Additionally, you can use the “Conditional Formatting” feature to visually highlight any differences between the two columns. By comparing two columns in Power BI, you can gain valuable insights and make informed decisions based on your data.

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.

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:

x