问题
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