Forum Discussion
How can I replace switch using dax
- 3 years ago
Hi, sanc_152
You can try the following methods.
Written measure = Var _Sales=SUM('Table'[Sales]) Var _Actuals=SUM('Table'[Actuals]) Var _Selected_=SELECTEDVALUE('Table'[Flag]) return SWITCH(TRUE(), _Selected_=1,_Actuals, OR(_Selected_=0,_Selected_=BLANK()),_Sales, _Sales )Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- 3 years ago
There are a few things that could be causing performance issues with your measure. One thing to consider is the use of the selectedvalue() function, which can be expensive and slow down your measure. Instead, you could try using a disconnected table to store the flag values and use a slicer to select the desired flag value.
Additionally, you could try simplifying your measure by combining the Sales and Actuals measures into one measure using an IF statement, rather than using the SWITCH function. Here's an example of how you could write the measure:
Sales and Actuals Measure = VAR SelectedFlag = SELECTEDVALUE(Product[Flag]) RETURN IF( SelectedFlag = 1, SUM(Actuals), SUM(Sales) )
This measure uses a single IF statement to check the selected flag value and return the appropriate sum value based on the flag. This should be simpler and more efficient than using the SWITCH function.
Hi, sanc_152
You can try the following methods.
Written measure =
Var _Sales=SUM('Table'[Sales])
Var _Actuals=SUM('Table'[Actuals])
Var _Selected_=SELECTEDVALUE('Table'[Flag])
return
SWITCH(TRUE(),
_Selected_=1,_Actuals,
OR(_Selected_=0,_Selected_=BLANK()),_Sales,
_Sales
)
Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.