The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event! Join us in Stockholm, Sweden from September 24-27, 2024.
2-for-1 sale on June 20 only!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
The following query works when none of the slicers on teh page are selected, but breaks when anyone of them is selected
Solved! Go to Solution.
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.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?
Proud to be a Super User!
@garimajain85 it seems that you are trying to calculate data from multiple tables which have no relationship?
And then when you select date filter, it breaks because it doesn't have relationship to one of tables.
In Excel iferror would fix error, but when working with Dax logic, we need to make sure data model is clean and correct.
So i would start from Calendar table (date slicer) and see to which table it is missing relationship and try to sort that out first.
Cheers,
Nemanja Andic
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
99 | |
93 | |
81 | |
63 | |
56 |
User | Count |
---|---|
247 | |
122 | |
110 | |
77 | |
72 |