【问题标题】:Multiple IF Statements in DAXDAX 中的多个 IF 语句
【发布时间】:2017-03-08 08:45:56
【问题描述】:

我目前在 Power BI 中制定了以下列数据,我需要将其显示在一列中,但将“1”替换为文本值:

原始列公式:

Age (18-27) = IF(AND([Age]>17, [Age]<28),"1",BLANK())
Age (28-35) = IF(AND([Age]>27, [Age]<36),"1",BLANK())
Age (36-43) = IF(AND([Age]>35, [Age]<44),"1",BLANK())
Age (44-50) = IF(AND([Age]>43, [Age]<51),"1",BLANK())
Age (50+) = IF([Age]>50,"1 ", BLANK())

输出:

Age (18-27) = IF(AND([Age]>17, [Age]<28),"Age (18-27)",BLANK())
Age (28-35) = IF(AND([Age]>27, [Age]<36),"Age (28-35)",BLANK())
Age (36-43) = IF(AND([Age]>35, [Age]<44),"Age (36-43)",BLANK())
Age (44-50) = IF(AND([Age]>43, [Age]<51),"Age (44-50)",BLANK())
Age (50+) = IF([Age]>50,"Age (50+) ", BLANK())

我想让公式在一列中显示数据,它正在合并输出公式(如上所示),所以我在一列中看到结果。

【问题讨论】:

  • 我想让公式在合并输出公式的一列中显示数据(如上所示),以便我在一列中看到结果。

标签: if-statement powerbi dax


【解决方案1】:

您可以像这样使用SWITCH(),它比嵌套的 IF 干净得多:

Age Group = SWITCH(TRUE(),
    AND([Age]>17, [Age]<28), "18-27",
    AND([Age]>27, [Age]<36), "28-35",
    AND([Age]>35, [Age]<44), "36-43",
    AND([Age]>43, [Age]<51), "44-50",
    [Age]>50, "50+", BLANK()
)

来源:https://community.powerbi.com/t5/Desktop/IF-or-SWITCH/m-p/167098#M72970

【讨论】:

    【解决方案2】:
    if you want to categorize the column value in the numerical range you can use below dax query.
    
    bubble = IF(AND([no_of_days_pending]>=100, [no_of_days_pending]<200),150,
     IF(AND([no_of_days_pending]>=200, [no_of_days_pending]<300),250,
      IF(AND([no_of_days_pending]>=300, [no_of_days_pending]<400),350,
       IF(AND([no_of_days_pending]>=400, [no_of_days_pending]<500),450,
        IF([no_of_days_pending]>=500,600, BLANK())
    ))))
    

    【讨论】:

      【解决方案3】:

      只需嵌套你的 IF:

      Age Group = IF(AND([Age]>17, [Age]<28),"18-27",
       IF(AND([Age]>27, [Age]<36),"28-35",
        IF(AND([Age]>35, [Age]<44),"36-43",
         IF(AND([Age]>43, [Age]<51),"44-50",
          IF([Age]>50,"50+", BLANK())
      ))))
      

      【讨论】:

      • 谢谢@user5226582
      猜你喜欢
      • 2022-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 2015-09-24
      相关资源
      最近更新 更多