im having 1 column contains number of hours, and i'm trying write down nested if statement in excel (or power bi since both have same syntax) but seems the code never reach other condition.
as per the image shows niether nested if nor the switch function works.
Your formula is wrong, since row 3 in your DAX code short circuits any value of Period
larger than 1
to return "2"
.
What you need is something where each successive test applies a gradually less strict constraint, in one direction:
ppp =
VAR _period = Sheet1[Period]
RETURN
SWITCH (
TRUE (),
_period <= 0, "-",
_period <= 1, "1 hour",
_period <= 2, "2 hours",
_period <= 3, "3 hours",
_period <= 4, "4 hours"
)