The IF function checks if a condition is fulfilled and returns one value in a positive case (if the evaluation of the condition returns the logical value True) and another in the negative case (if the evaluation of the condition returns the logical value False).
IF(
logical_test,
value_if_true
[, value_if_false]
)
- logical_test: Condition to evaluate (which must return a True or False value) that will determine the return of the value value_if_true or the value value_if_false.
- value_if_true: Value to return if the logical_test condition is evaluated as true.
- value_if_false: Optional parameter. Value to return if the logical_test condition is evaluated as false.
The IF function can return a value of any type.
If logical_test refers to a column, the IF function returns the appropriate value for the current row. In this case, IF tries to return the same type of value for all rows. If the type of value_if_true and the type of value_if_false are different, IF will implicitly convert the results to ensure that they all have the same type. If this is not possible (by returning, for example, a text string in one case and a number or a Boolean in another), the function returns an error message:
The value_if_true argument is required. In case the value_if_false argument is not included, the IF function returns a Blank (see example below).
In this example, each sale is evaluated as "Gran venta" ("Big Sale") or "Pequeña venta" ("Small Sale") depending on whether or not the amount of the sale is greater than € 100,000:
The value_if_false argument is not included in this example. To confirm the type of the result that the IF function returns in the event that logical_test evaluates to False, a new custom column is added with the formula:
Es blank = ISBLANK(Tabla1[Tipo de venta])
- Add an exception to the results returned by a measure
- Evaluating a value from a list
- Using variables in DAX expressions
- Name of the best selling product
- Calculation of the number of days between purchases
- Calculation of the fiscal year and month corresponding to each date
- Marking days as working or non-working days
- Calculation of an expression only if the values involved are not null