How do you write an IF statement in Power BI, and can you provide an example?

An IF statement in Power BI allows users to create conditional logic that determines which data should be displayed based on a certain condition. To write an IF statement, the syntax is “IF <>, <>, <>”. An example of this could be “IF [Sales]>10000, “High”, “Low” which would display “High” if the sales are greater than 10,000 and “Low” if they are not. This allows for more dynamic and customizable data analysis in Power BI.

Write an IF Statement in Power BI (With Example)


You can use the following syntax in DAX to write an IF statement in Power BI:

Method 1: Write an IF Statement

Rating = 
IF(
    'my_data'[Points] > 20,
    "Good",
    "Bad"
)

This particular syntax creates a new column named Rating that returns “Good” if the value in the Points column is greater than 20 or “Bad” otherwise.

Method 2: Write a Nested IF Statement

Rating = 
IF(
    'my_data'[Points] < 20,
    "Bad",
    IF(
        'my_data'[Points] <30,
        "Good",
        "Great"
    )
)

This particular syntax creates a new column named Rating that returns the following values:

  • “Bad” if the value in the Points column is less than than 20
  • Else, “Good” if the value in the Points column is less than 30
  • Else, “Great”

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

Example 1: Write an IF Statement in Power BI

Suppose we would like to add a new column that contains “Good” if the value in the Points column is greater than 20 or “Bad” otherwise.

To do so, click the New column icon:

Then type in the following formula into the formula bar:

Rating = 
IF(
    'my_data'[Points] > 20,
    "Good",
    "Bad"
)

This will create a new column named Rating that contains the value “Good” or “Bad” based on the corresponding value in the Points column:

Power BI IF statement

Example 2: Write a Nested IF Statement in Power BI

Suppose we would like to add a new column that contains “Bad” if the value in the Points column is less than 20, else “Good” if the value in the Points column is less than 30, else “Great” if neither of the previous conditions are met.

To do so, click the New column icon:

Then type in the following formula into the formula bar:

Rating = 
IF(
    'my_data'[Points] < 20,
    "Bad",
    IF(
        'my_data'[Points] <30,
        "Good",
        "Great"
    )
)

This will create a new column named Rating that contains the value “Bad’, “Good” or “Great” based on the corresponding value in the Points column:

Power BI nested IF statement

Note: You can find the complete documentation for the IF function in DAX .

Additional Resources

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

x