Menu
CoddyTech

用 SWITCH(TRUE()) 处理范围

本课属于 Coddy Power BI 学习旅程的“使用 CALCULATE 编写 DAX”单元。第 20 课,共 24 课。

SWITCH(TRUE(), test1, result1, test2, result2, else):第一个为真的测试会胜出。

Price Band = SWITCH(TRUE(), Products[UnitPrice] >= 10, "Premium", Products[UnitPrice] >= 4, "Standard", "Budget")

先放范围最窄的测试,否则范围更广的测试会捕获它对应的行。

challenge icon

挑战

简单

在 Products 中添加一列 Price Band:单价大于或等于 10 时为 "Premium",大于或等于 4 时为 "Standard",其余情况为 "Budget"。

亲手试试

Price Band =
ProductCategoryPrice Band
EspressoCoffee
LatteCoffee
CappuccinoCoffee
字段
  • Sales
  • Products
    • ProductID
    • Product
    • Category
    • UnitPrice
    • UnitCost
  • Stores
  • Customers
  • Dates
  • Targets

使用 CALCULATE 编写 DAX中的所有课