Forum Discussion
Dynamic DAX Variable
- 1 year ago
Hi fergu513,
Thank you for the update.
Please follow the steps outlined below, which may assist in resolving the issue:
-
DAX cannot track the order of slicer selections; therefore, the best approach is to control behavior based on drill level visibility using ISINSCOPE():
VAR TotalGMPY =
SWITCH(
TRUE(),
ISINSCOPE(GPH[GPH Level2]), CALCULATE([TotalGM PY], REMOVEFILTERS(GPH[GPH Level1])),
ISINSCOPE(GPH[GPH Level1]), CALCULATE([TotalGM PY], REMOVEFILTERS(PS_TYPE[PS_TYPE])),
ISINSCOPE(PS_TYPE[PS_TYPE]), CALCULATE([TotalGM PY], REMOVEFILTERS(Manufacturer[VENDOR_NAME])),
CALCULATE([TotalGM PY])
)
This measure makes the calculation responsive to the matrix drill level, even when multiple slicer values are selected. -
The SELECTEDVALUE() function returns a blank if multiple values are selected, which causes the SWITCH() function to fall into the default case. We can rectify this by using ISINSCOPE() or VALUES() instead of SELECTEDVALUE() when supporting multi-selections, or by limiting the slicer to single-select.
If you find our response helpful, kindly mark it as the accepted solution and provide kudos. This will assist other community members who face similar queries.
Thank you.
-
What if the user selected multiple options from Add Rows and I want the TotalGMPY to change based on what level you are viewing within the matrix?
For example, if they select PS_TYPE, GPH Level 1, and GPH Level 2, in that order: i want TotalGMPY in the GPH Level 2 level to REMOVEFILTERS(GPH Level 1) and then TotalGMPY in the GPH Level 1 level to REMOVEFILTERS(PS_Type).
How can I make this happen dynamically?