case statement in Dax

雨燕双飞 提交于 2020-06-27 12:45:18

问题


I have the following case when statement:

case when ts.wgt_kg / ((hgt_cm / 100) * (hgt_cm / 100)) < 18.5 then 'Underweight < 18.5'
when ts.wgt_kg / ((hgt_cm / 100) * (hgt_cm / 100)) between 18.5 and 24.9 then 'Normal 18.5-24.9'
when ts.wgt_kg / ((hgt_cm / 100) * (hgt_cm / 100)) between 25.0 and 29.9 then 'Overweight 25-29.9'
when ts.wgt_kg / ((hgt_cm / 100) * (hgt_cm / 100)) > 30.0 then 'Obese > 30.0'
end as BMI

How can i convert it into DAX? I tried to google it but I wasn't able to find anything useful. Can someone help me with that please. Thanks


回答1:


Try something along these lines:

BMI Category =
VAR BMI = ts.wgt_kg / ( ( hgt_cm / 100 ) * ( hgt_cm / 100 ) )
RETURN
    SWITCH (
        TRUE (),
        BMI < 18.5, "Underweight < 18.5",
        BMI < 25.0, "Normal 18.5-24.9",
        BMI < 30.0, "Overweight 25-29.9",
        "Obese > 30.0"
    )

This will return the first condition that evaluates to true or use the last argument if none of the above are true.



来源:https://stackoverflow.com/questions/47834964/case-statement-in-dax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!