首页 > 解决方案 > 使用switch作为嵌套comaprison的Dax错误

问题描述

嗨,我正在尝试根据两个度量值获得最后一列,我正在使用 Power BI,但我是新手。这是公式。我收到一个错误“功能开关不支持将真/假类型的值与文本类型的值进行比较”

SWITCH(
    AND(('Table'[ar]*100)>=-100,('Table'[ar]*100)<=-5),
        SWITCH(
          AND(('Table'[br]*100)>=-5,('Table'[br]*100)<=5),"DROP TO AVG",
          AND(('Table'[br]*100)<=100,('Table'[br]*100)>=5),"DROP TO HIGH",
          AND(('Table'[br]*100)>=-100,('Table'[br]*100)<=-5),"BAD ALERT"),
    AND(('Table'[ar]*100)>=-5,('Table'[ar]*100)<=5),
        SWITCH(
          AND(('Table'[br]*100)<=100,('Table'[br]*100)>=5),"KEEP HIGH",
          AND(('Table'[br]*100)>=-100 ,('Table'[br]*100)<=-5),"KEEP LOW"),
    AND(('Table'[ar]*100)<=100,('Table'[ar]*100)>=5),
        SWITCH(
          AND(('Table'[br]*100)>=-5,('Table'[br]*100)<=5),"INCREASE TO AVG",
          AND(('Table'[br]*100)>=-100,('Table'[br]*100)<=-5),"INCREASE TO LOW",
          AND(('Table'[br]*100)<=100,('Table'[br]*100)>=5),"GOOD ALERT"))

标签: powerbidax

解决方案


您会收到该错误,因为您有一些放错位置的括号,其中包含AND函数中的文本。例如AND(('Table'[br]*100)>=-100,('Table'[br]*100)<=-5),"BAD ALERT"),。文本不能在逻辑上与 True/False 组合。

我认为您正在寻找更像这样的东西:

SWITCH(TRUE(),
    ('Table'[ar]*100 >= -100) && ('Table'[ar]*100 <= -5),
    SWITCH(TRUE(),
        ('Table'[br]*100 >=  -5 ) && ('Table'[br]*100 <=  5), "DROP TO AVG",
        ('Table'[br]*100 <=  100) && ('Table'[br]*100 >=  5), "DROP TO HIGH",
        ('Table'[br]*100 >= -100) && ('Table'[br]*100 <= -5), "BAD ALERT"
    ),
    ('Table'[ar]*100 >= -5) && ('Table'[ar]*100 <=5),
    SWITCH(TRUE(),
        ('Table'[br]*100 <=  100) && ('Table'[br]*100 >=  5), "KEEP HIGH",
        ('Table'[br]*100 >= -100) && ('Table'[br]*100 <= -5), "KEEP LOW"
    ),
    ('Table'[ar]*100 <= 100) && ('Table'[ar]*100 >= 5),
    SWITCH(TRUE(),
        ('Table'[br]*100 >=  -5 ) && ('Table'[br]*100 <=  5), "INCREASE TO AVG",
        ('Table'[br]*100 >= -100) && ('Table'[br]*100 <= -5), "INCREASE TO LOW",
        ('Table'[br]*100 <=  100) && ('Table'[br]*100 >=  5), "GOOD ALERT"
    )
)

推荐阅读