Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
garimajain85
Regular Visitor

Measure not working with Slicers: DAX

The following query works when none of the slicers on teh page are selected, but breaks when anyone of them is selected

Eff.Monthly Avg. Productivity =
IFERROR([Eff.Month Total Productivity]/[Active UA Population],CALCULATE([Eff.Month Total Productivity]/88)).
I am trying to create a measure for the following conditions:
If no  date filters are selected:
                             Divide (Total Sales by Active count of employees)
 If the selected month= any of the past month
                             Divide (Total Sales   by Active count of employees in the respective month)
If the selcted month= future month
                               Divide (Total Sales   by Max(Active count of employees in previous months)
If any other filters is selected example(manager name)
                          Then the above measures should work accordingly. So                        
                                           If the selected month= any of the past month
                                                       Divide (Total Sales for the manager / Active count of employees in his team in the respective month)
 
 
3 REPLIES 3
v-linyulu-msft
Community Support
Community Support

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:

vlinyulumsft_0-1716459375653.png
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.

vlinyulumsft_1-1716459467894.png

vlinyulumsft_2-1716459488335.png

vlinyulumsft_3-1716459506647.png

vlinyulumsft_4-1716459534973.png

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.

danextian
Super User
Super User

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?










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
nandic
Memorable Member
Memorable Member

@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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.