Forum Discussion
Using variable result in another Variable?
I'm definitely struggling with this today, and I think the issue may have something to do with the ability to pass a variable meaure into the Calculate function?
I tried with the field paramater, and also tried @dharmendars007 code, and get the same incorrect value.
If I place the Switch statement directly within the Calculate function, it works as expected. But if change out the Switch statement with variable name in the Calculate, it returns an incorrect value?
Can you use a variable measure in Calculate?
EDIT. Pretty sure you can't use the Variable in the Calculate, and finally found an explanation here that makes sense. The Variable gets totaled before the filtering in the Calculate, thus the wrong response is given.
https://radacad.com/caution-when-using-variables-in-dax-and-power-bi
Occupied Rooms =
VAR _Period = SWITCH (
VALUES ('Measures List'[Fact Period]),
"Day", [QTY],
"Last 7", [Last 7 QTY],
"MTD", [MTD QTY],
"QTD", [QTD QTY],
"YTD", [YTD QTY]
)
RETURN
CALCULATE(
SWITCH (
VALUES ('Measures List'[Fact Period]),
"Day", [QTY],
"Last 7", [Last 7 QTY],
"MTD", [MTD QTY],
"QTD", [QTD QTY],
"YTD", [YTD QTY]
)
,'Dim Item'[description]="OCCUPIED ROOMS"
)