Forum Discussion
Measure not working with Slicers: DAX
- Anonymous2 years ago
Hi,garimajain85.Hello, danextian, nandic.Thank you very much for your help with this issue.
And now I want to share my advice with you.
I am glad to help you.Regarding the issue you raised, my solution is as follows:
1.First on your first question, the reason why metrics are affected when using a slicer is because the slicer changes the context, which may cause some metrics to return an error in that context, here's a link to that:Context in DAX Formulas - Microsoft Support
2.First I have created the following table and the column names and data are the data you have given:
3. Below are the measure I've created for your needs:Measure 2 = SWITCH(TRUE(), ISFILTERED('M'[manager]),IF(MONTH(SELECTEDVALUE(MON[1]))=MONTH(TODAY())-1, DIVIDE(CALCULATE(SUM('IFERROR'[Active count of employees]),FILTER(ALLSELECTED('IFERROR'),'IFERROR'[manager]=MAX('IFERROR'[manager]))),AVERAGE('IFERROR'[Active count of employees])), FALSE()), SELECTEDVALUE(MON[1])<=TODAY(),DIVIDE(CALCULATE(SUM('IFERROR'[SALE]),FILTER(ALLSELECTED('IFERROR'),MONTH('IFERROR'[month])=MONTH(SELECTEDVALUE(MON[1])))), CALCULATE(SUM('IFERROR'[Active count of employees]),FILTER(ALLSELECTED('IFERROR'),MONTH('IFERROR'[month])=MONTH(SELECTEDVALUE(MON[1]))))), SELECTEDVALUE(MON[1])>TODAY(),DIVIDE(SUM('IFERROR'[SALE]), CALCULATE(MAX('IFERROR'[Active count of employees]),FILTER(ALLSELECTED('IFERROR'),MONTH('IFERROR'[month])<MONTH(SELECTEDVALUE(MON[1]))))), FALSE())Measure = VAR _a = SELECTEDVALUE('MON'[1]) RETURN IF(_a =BLANK(),DIVIDE(SUM('IFERROR'[SALE]),SUM('IFERROR'[Active count of employees])), [Measure 2])4.Here's my final result, which I hope meets your requirements.
Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hI garimajain85 ,
When you say breaks what exactly happens?
It's hard to figure what could be wrong without seeing what each measure does in response to a slicer selection.
Can you please share a sanitized copy of your pbix?