Forum Discussion
Calculated Measure not working in the Matrix
- 6 years ago
Whoops sorry:
CALCULATE(DISTINCTCOUNT('Quotes Estimates US'[Customer]),FILTER('Quotes Estimates US','Quotes Estimates US'[Job Start Year] = YEAR('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Job Start Month] = MONTH('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Customer Status] = "A"))
Hi Anonymous ,
ALLSELECTED removes the Row and Column filter.
https://docs.microsoft.com/en-us/dax/allselected-function-dax
Regards,
Marcus
Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.
Taking out the All Selected makes the cards wrong so I feel like it is needed.
- JarroVGIT6 years agoResident Rockstar
Hi Anonymous ,
Thanks for sharing the screenshots. You stated you felt that the ALLSELECTED needs to be in there because otherwise the cards are off. However, Let me explain what your measure actually does:
CALCULATE( //we are going to calculate something BUT with a different context. You can give a totally NEW context by using FILTER or manipulate the CURRENT context by using statements like [col1] = "A". DISTINCTCOUNT('Quotes Estimates US'[Customer]), //You want the distinct count of the column Customer, but with a totally NEW context (not modified from the current context!) FILTER(ALLSELECTED('Quotes Estimates US'), //You are creating a NEW context by looking at the dataset filtered by explicit filters (like slicers) from outside the current evaluation context. So this returns all the rows from the dataset, based on the current selection of page or report filters or slicers. The current visual is not taken into account. 'Quotes Estimates US'[Job Start Year] = YEAR('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Job Start Month] = MONTH('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Customer Status] = "A")) //Here you are filtering the NEW context for rows where the above evaluates to TRUE.So the context you create by using the FILTER(ALLSELECTED()) statement is the same wether you evaluate this in a Matrix or a Card. However, in the Card visual, the current data context is the same as the context you create with FILTER(ALLSELECTED()). I can think of two reasons why this would result in a different outcome:
- You have a Visual Filter applied on the Card visual (on the Filters pane), or
- You have edited the interactions between the slicers and the Card visual.
If neither is the case, then removing ALLSELECTED() should return the same value. Now moving on to your Matrix visual. Normally, the Measure is evaluated per every row/column combination. That row/column essentially filters the dataset (current context), so in your case it would filter the data context first with the slicers, but then would filter it down further based on the SalesPersons column. However, because you recreate your entire context with FILTER(ALLSELECTED()), it ignores the SalesPerson column filter that it gets from the Matrix visual.
So the remaining question is: what value do you expect to be in the Card when you apply the slicers in your report? You want the card to be responsive to the Year and Month slicers, but always show 175 New Customer Quotes regardless of the what a user selects from the other slicers? Because then you should just turn off the interactions of the slicers you don't want to have an impact on the cards.
Let me know if this solves your issue. I decided to respond in the thread because the explanation of how the context works in you measure when it is evaluated might be of interest of others.
Kind regards
Djerro123
-------------------------------
If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.
Keep those thumbs up coming! 🙂
- Anonymous6 years agoNot applicable
Hi so I checked and there is nothing be filtered on either the cards or the page to cause the difference between the two when in card form vs being in the matrix. So the point of the cards is to highlight at a high level the number of new customers and quotes that they have for a given time frame determines by the date chiclets. A new customer has the status of A, and the customer creation date occurs during the same month as the what is being filtered for on the page then that customer counts as a new customer and I want to count the number of quotes assoicated wtih them. It took me a lot of reserach to get a function that worked. How do you suggest I modify the function?
CALCULATE(DISTINCTCOUNT('Quotes Estimates US'[Customer]),FILTER(ALLSELECTED('Quotes Estimates US'),'Quotes Estimates US'[Job Start Year] = YEAR('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Job Start Month] = MONTH('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Customer Status] = "A"))
- JarroVGIT6 years agoResident Rockstar
Like I suggested in my previous post, remove the interaction between the slicers and the Card visual except for the Year and Month slicers. Check this tutorial to see how to do that: https://docs.microsoft.com/en-us/power-bi/service-reports-visual-interactions
Then the formula is:
CALCULATE(DISTINCTCOUNT('Quotes Estimates US'[Customer]),'Quotes Estimates US'[Job Start Year] = YEAR('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Job Start Month] = MONTH('Quotes Estimates US'[Customer Created Date])&&'Quotes Estimates US'[Customer Status] = "A")That should work and fit your requirements. Please re-read my explanation on context as I don't think you fully grasped it yet. If you want a Card measure to be ignorant of your selection in Slicers, then give it a NEW context.
Kind regards
Djerro123
-------------------------------
If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.
Keep those thumbs up coming! 🙂
- JarroVGIT6 years agoResident RockstarHi Reh169,
Is it possible to share your pbix file (please remove confidential data)? If you don't want to share publicly you can share via PM with me and I will have a look tonight.