DAX Logical - IF function



Description

Checks a condition given as the first argument of the function and returns one value if the condition is TRUE and returns another value if the condition is FALSE.

Syntax

IF (<logical_test>, <value_if_true>, [<value_if_false>])

Parameters

Sr.No. Parameter & Description
1

logical_test

Any value or expression that can be evaluated to TRUE or FALSE.

2

value_if_true

The value that is returned if the logical test is TRUE.

3

value_if_false

Optional.

The value that is returned if the logical test is FALSE.

If omitted, FALSE is returned.

Return Value

Any type of value that can be returned by an expression.

Remarks

  • If value_if_false is omitted, IF treats it as an empty string value ("").

  • If the value referenced in the logical_test is a column, IF returns the value that corresponds to the current row. Thus, the IF function returns a column of all the values resulting from the logical test corresponding to each of the rows.

  • If you have 3 values to return, then you can nest the IF functions.

Example

=IF([Country]="USA",1,0)

Returns a calculated column of 1’s and 0’s. These values can be summed up.

If you name the column as USA Medals, then you can write the following −

then you can write the following -

dax_functions_logical.htm
Advertisements