IF

Updated on

IF is a DAX function that checks a condition and returns one value if TRUE and another value if FALSE.

Syntax

IF(
   LogicalTest,
   ResultIfTrue,
   ResultIfFalse
)
Argument Properties Description
LogicalTest Any value or expression that can be evaluated to TRUE or FALSE.
ResultIfTrue The value that is returned if the logical test is TRUE.
ResultIfFalse Optional The value that is returned if the logical test is FALSE; if omitted, BLANK is returned.

Return Values

Either value_if_true, value_if_false, or BLANK.

Remarks

  • The IF function can return a variant data type if value_if_true and value_if_false are of different data types, but the function attempts to return a single data type if both value_if_true and value_if_false are of numeric data types. In the latter case, the IF function will implicitly convert data types to accommodate both values.

    For example, the formula IF(<condition>, TRUE(), 0) returns TRUE or 0, but the formula IF(<condition>, 1.0, 0) returns only decimal values even though value_if_false is of the whole number data type. To learn more about implicit data type conversion, see Data types.

  • To execute the branch expressions regardless of the condition expression, use IF.EAGER instead.

Examples

The following Product table calculated column definitions use the IF function in different ways to classify each product based on its list price.

The first example tests whether the List Price column value is less than 500. When this condition is true, the value Low is returned. Because there’s no value_if_false value, BLANK is returned.

Examples in this article can be used with the sample Adventure Works DW 2020 Power BI Desktop model. To get the model, see DAX sample model.

Price Group =
IF(
    'Product'[List Price] < 500,
    "Low"
)

The second example uses the same test, but this time includes a value_if_false value. So, the formula classifies each product as either Low or High.

Price Group =
IF(
    'Product'[List Price] < 500,
    "Low",
    "High"
)

The third example uses the same test, but this time nests an IF function to perform an additional test. So, the formula classifies each product as either Low, Medium, or High.

Price Group =
IF(
    'Product'[List Price] < 500,
    "Low",
    IF(
        'Product'[List Price] < 1500,
        "Medium",
        "High"
    )
)

Tip

When you need to nest multiple IF functions, the SWITCH function might be a better option. This function provides a more elegant way to write an expression that returns more than two possible values.

Other functions related to IF are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/if-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy