SWITCH(TRUE()) for Ranges
Part of the DAX with CALCULATE section of Coddy's Power BI journey. Lesson 20 of 24.
SWITCH(TRUE(), test1, result1, test2, result2, else): the first true test wins.
Price Band = SWITCH(TRUE(), Products[UnitPrice] >= 10, "Premium", Products[UnitPrice] >= 4, "Standard", "Budget")Put the narrowest test first, or a wider test catches its rows.
Challenge
Add a column Price Band to Products: "Premium" for a unit price of 10 or more, "Standard" for 4 or more, and "Budget" for the rest.
All lessons in DAX with CALCULATE
1Changing the Filters
Meet CALCULATEA Filter Replaces a FilterSeveral Filters at OnceKeeping FiltersRecap - Member Drink Sales4DAX You Can Read
Variables with VARChoosing with SWITCHSWITCH(TRUE()) for RangesOne Value or ManyRows or the TotalChecking Copilot's DAXRecap - Sales by Price Band