We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Logical Functions – IF

Logical functions let your DAX formulas make decisions based on conditions. With them you can label rows, create flags, or change calculations depending on your data.

In the sales dataset, we might want to mark which orders are bulk orders, or whether a sale has a discount applied. Logical functions like IF and SWITCH are perfect for this.

Logical functions turn your numbers into rules the business actually cares about.

You will typically use logical functions in:

  • Calculated columns, for row-by-row labels
  • Measures, for dynamic classification based on filters

IF Function

The IF function checks a condition and returns one value if true, another if false. Here's an example of an IF function that labels homes as "Jumbo" or "Normal" based on whether their price is above $700,000:

HouseType = IF(Homes[Price] > 700000, "Jumbo", "Normal")

Notice that it has 3 parameters:

  • Logical Test: The condition to check (e.g., Homes[Price] > 700000)
  • Value if True: What to return if the condition is true (e.g., "Jumbo")
  • Value if False: What to return if the condition is false (e.g., "Normal")

and returns the value as HouseType.

Assignment

Save the project and, from the course directory, submit the CLI tests.