DAX中的多个IF报表

时间:2016-10-26 05:44:48

标签: if-statement powerbi dax

我目前在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())

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

4 个答案:

答案 0 :(得分:4)

只需嵌套您的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())
))))

答案 1 :(得分:4)

您可以像这样使用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 :(得分:0)

我也有同样的问题..我有多个列,我想生成一个组合它们的单个列..

我可以使用switch case公式对两列进行此操作,但不能超过两列

SWITCH(,, [,,] ...... [,])

答案 3 :(得分:0)

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())
))))