Multiple IF Statements in DAX

Rush picture Rush · Oct 26, 2016 · Viewed 47.8k times · Source

I currently have Column Data formulated below in Power BI which I need for it to display in one column but replacing the "1" with a Text value being:

Orginal column formula:

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

Output:

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

I would like to have the formula display the data in one column where it is consolidating the Output formula (seen above) so I see the results in one column.

Answer

user5226582 picture user5226582 · Oct 26, 2016

Just nest your IFs:

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