IF and SWITCH

With IF and SWITCH a formula decides based on a value: high or low, premium or entry, target met or not. It works in a measure just as in a calculated column.

In short: IF(condition, then, else) works like IF in Excel. For several bands, use SWITCH(TRUE(), condition1, result1, condition2, result2, else): it returns the result of the first condition that is true.

Before this: DIVIDE and Calculated columns.

Try it now

Task Create the measure "Sales Class": "High" if [Total Sales] is at least 10000, otherwise "Low".

Sales 120 rows, 7 columns
OrderIDOrderDateShipDateProductIDRegionIDQuantityAmount
13 Oct 20266 Oct 20261221798
29 Nov 202519 Nov 20252351145
320 Sep 202627 Sep 2026544596
416 Jun 20252 Jul 20252151145
526 Mar 202631 Mar 20261343596
64 Dec 202510 Dec 2025545745
78 Jul 202526 Jul 2025614196
820 Feb 20251 Mar 202532359.7
99 Dec 202524 Dec 202562298
1012 Aug 202625 Aug 2026212458
117 Sep 202612 Sep 2026542298
122 Mar 202614 Mar 2026623147

Showing the first 12 of 120 rows.

Measures: [Total Sales]

Product 6 rows, 4 columns
ProductIDProductCategoryPrice
1LaptopHardware899
2MonitorHardware229
3MouseAccessories19.9
4KeyboardAccessories39.9
5Office suiteSoftware149
6AntivirusSoftware49
Region 4 rows, 2 columns
RegionIDRegion
1North
2South
3West
4East
Date 730 rows, 4 columns
DateYearMonthMonthName
1 Jan 202520251Jan
2 Jan 202520251Jan
3 Jan 202520251Jan
4 Jan 202520251Jan
5 Jan 202520251Jan
6 Jan 202520251Jan
7 Jan 202520251Jan
8 Jan 202520251Jan
9 Jan 202520251Jan
10 Jan 202520251Jan
11 Jan 202520251Jan
12 Jan 202520251Jan

Showing the first 12 of 730 rows.

IF

IF tests a condition and returns one of two values. Text goes in double quotes. Without the third argument, the result is blank when the condition is false.

In a measure, IF tests the result of each cell: in the Laptop row the laptop sales, in the total row the total sales. A measure that returns text suits tables and matrices, not a bar chart.

SWITCH(TRUE(), …) for bands

With three or more bands, nested IFs quickly become unreadable. SWITCH with TRUE() as its first argument tests the conditions in order and returns the result of the first one that is TRUE. The last argument without a partner is the value for all remaining cases.

Order decides: if the lowest limit comes first, it matches almost everything and the higher bands never get a turn.

Task Create the calculated column "Price Band" in Product: "Premium" from a price of 500, "Mid" from 100, otherwise "Entry". Use SWITCH(TRUE(), …).

Sales 120 rows, 7 columns
OrderIDOrderDateShipDateProductIDRegionIDQuantityAmount
13 Oct 20266 Oct 20261221798
29 Nov 202519 Nov 20252351145
320 Sep 202627 Sep 2026544596
416 Jun 20252 Jul 20252151145
526 Mar 202631 Mar 20261343596
64 Dec 202510 Dec 2025545745
78 Jul 202526 Jul 2025614196
820 Feb 20251 Mar 202532359.7
99 Dec 202524 Dec 202562298
1012 Aug 202625 Aug 2026212458
117 Sep 202612 Sep 2026542298
122 Mar 202614 Mar 2026623147

Showing the first 12 of 120 rows.

Measures: [Total Sales]

Product 6 rows, 4 columns
ProductIDProductCategoryPrice
1LaptopHardware899
2MonitorHardware229
3MouseAccessories19.9
4KeyboardAccessories39.9
5Office suiteSoftware149
6AntivirusSoftware49
Region 4 rows, 2 columns
RegionIDRegion
1North
2South
3West
4East
Date 730 rows, 4 columns
DateYearMonthMonthName
1 Jan 202520251Jan
2 Jan 202520251Jan
3 Jan 202520251Jan
4 Jan 202520251Jan
5 Jan 202520251Jan
6 Jan 202520251Jan
7 Jan 202520251Jan
8 Jan 202520251Jan
9 Jan 202520251Jan
10 Jan 202520251Jan
11 Jan 202520251Jan
12 Jan 202520251Jan

Showing the first 12 of 730 rows.

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

SWITCH with fixed values

SWITCH can also compare an expression with fixed values, for example SWITCH('Date'[Month], 1, "Jan", 2, "Feb", "other"). That is the equivalent of CHOOSE or SWITCH in Excel.

In real Power BI

  1. For a band per product: select the Product table in the Data pane, choose New column and type the formula.
  2. The new column can go into rows, axes and slicers like any column.
  3. For a band that depends on filters (sales class), create a measure.

Common mistakes

Text without quotes

IF([Total Sales] >= 10000, High, Low) looks for columns or measures named High and Low. Text needs double quotes.

Date without quotes

In DAX, Date is a reserved word. A table called Date must be written 'Date'[Month] in front of a column; Date[Month] is a syntax error in Power BI.

FAQ

Column or measure for a classification?

If the band depends only on the row, such as the list price, it is a column. If it depends on a total that changes with the filters, it is a measure.

Is there an IFS like in Excel?

No. That is what SWITCH(TRUE(), …) is for.

Up next: filter context

Why the same measure shows something different in every cell, and how to ask about it.

Next lesson

Write to us

Choose language

Select your preferred language