Power BI IF Statement

IF Statement in Power BI

If you don’t know logical functions, then you cannot pursue a career as an analyst. Yes, this is absolutely TRUE. Without knowing logical functions, you cannot deal with a different set of calculations where the calculation requires you to test multiple logical tests in excelLogical Tests In ExcelA logical test in Excel results in an analytical output, either true or false. The equals to operator, “=,” is the most commonly used logical test.read more. The IF condition is the boss when it comes to logical tests, whether its an excel or Power BI anywhere IF statement is the boss. If you have already used the IF condition in Excel, then using it with Power BI is exactly the same. In this article, we will take you through how to apply logical IF statement in Power BI DAX formulas.

Power-BI-IF-Statement

You are free to use this image on your website, templates etc, Please provide us with an attribution linkHow to Provide Attribution?Article Link to be Hyperlinked
For eg:
Source: Power BI IF Statement (wallstreetmojo.com)

What is IF DAX Statements in Power BI?

IF is a logical function in both Excel & Power BI, so it used to arrive results based on logical results. Logical results are in two ways i.e., either TRUE or FALSE, so we can arrive two results based on the result of the logical test if the logical test is TRUE, one set of result or calculation and if the logical tests are FALSE second set or alternative to the first set of result.

Below is the syntax of the IF DAX statement in Power BI.

Power BI IF Syntax
  • Logical Test: For this, we need to apply what is the logical test to arrive results.
  • Result If True: If the logical test is TRUE, then what should be the result.
  • Result If False: If the logical test is FALSE, then what should be the alternative result to the first one.

If you ignore the Result If False, then we will get BLANK as a result.

Examples of IF DAX Statement in Power BI

Below are examples of the IF statement in Power BI. You can download the workbook to use the same file as we used in this example.

You can download this Power BI IF Statement Excel Template here – Power BI IF Statement Excel Template

Example #1

Power BI IF - Table Data

With this data, we need to arrive new column, i.e., “Status.”

To arrive this new column, we have a certain criterion, i.e. “if the temperature is >25, then the status should be “High,” or else status should be “Medium.”

For example, look at the above set of data tables to apply the Power BI IF statement.

  1. Copy the above table to the Power BI file.


    Power BI IF - Table

  2. Right-click on the table and choose “New Column.”


    Power BI IF - New Column

  3. First, give a name to this new column as “Status.”

    Power BI IF - Status

  4. Open IF DAX Statement now.

    Power BI IF - IF Syntax

  5. The logical test is to check whether the temperature is >25 or not, so first select the temperature column and then apply the logical test as shown below.

    Power BI IF - IF Condition
    Once the logical test is applied, we need to mention what the result should be if the logical test is TRUE.

  6. So our result if the logical tests are TRUE i.e., If the temperature is >25, then we need the result as “High,” mention the result in double-quotes.

    Power BI IF - IF Condition - High

  7. Now, if the result is false, then we need the result as “Low.”

    Power BI IF - IF Condition - Low

  8. Close the bracket and hit the enter key to get the result column.

    Power BI IF - IF Result

Wow, there we have a new result column with a logical IF formula.

Example #2

Now assume that instead of arriving only two sets of results, we need to arrive multiple results based on multiple logical tests.

For example:

  • If the temperature is >30, status is “Heavy.”
  • If the temperature is >28, status is “High.”
  • If the temperature is >25, status is “Moderate.”
  • If the temperature is <=25, then we need the status as “Low.”

Here we need to test 4 different logical tests, so this requires nested IF conditionsNested IF ConditionsIn Excel, nested if function means using another logical or conditional function with the if function to test multiple conditions. For example, if there are two conditions to be tested, we can use the logical functions AND or OR depending on the situation, or we can use the other conditional functions to test even more ifs inside a single if.read more to be applied.

  • Open IF condition and apply the first logical test.
IF Condition - Heavy
  • The first logical condition is applied. Now we need to test other logical tests if this logical test is FALSE, so since we need to test other logical tests, open one more IF condition.
Power BI IF - IF Condition 2.1
  • This IF condition applies a second logical test and arrives the result if this logical test is TRUE.
 IF Condition High 2
  • Similarly, IF both these logical tests are FALSE, we need to do another logical test, so open another IF condition.
Power BI IF - IF Condition - Moderate
  • Like this, we have to do one more logical test if all these three logical tests are FALSE. But instead of opening one more IF condition, we can make use of the last argument i.e., “Result If False,” so this argument will be employed or used if all the applied logical tests are FALSE. So if all these are FALSE, then we need the result as “Low.”
 IF Condition - Low Condition
  • Now close brackets as many as IF conditions opened. After closing, the bracket, hit the enter key to get the new status result.
Power BI IF - IF Result 2.1

Here we have the results, like this, we can use the IF DAX function to get the conditional calculation column.

Note: Power BI IF statement file can also be downloaded from the link below, and the final output can be viewed.

You can download this Power BI IF Statement Template here – Power BI IF Statement Template

Things to Remember here

  • IF DAX function is the same as Excel IF logical function, all the arguments and application methods, everything is the same.
  • In case of multiple conditions to arrive single result, then we need to use AND & OR logical functions.
  • AND logical function is represented by the double ampersand (&&), and OR logical function is represented by double straight lines (||).

This has been a guide to Power BI IF Statement. Here we discuss how to apply the IF function in Power BI Dax formulas with the help of examples. You can learn more from the following Power BI articles –

  • 35+ Courses
  • 120+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>