Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calculated Measure not working in the Matrix

So I created a calculated measure to count the number of new customers and new customer quotes each month. See logic below. I also have a matrix where I have all the sales people listed and I want to be able to add these measures to the matrix and see the break down there. When I add them it gives me the total number for month for every person. But if I filter the page by sales person then the tiles that show the measures above adjust so I know that the connection is there. How do I get it to reflect accurately in the matrix as well?

 

  • 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"))
  • 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"))

12 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Taking out the All Selected makes the cards wrong so I feel like it is needed.

      • JarroVGIT's avatar
        JarroVGIT
        Resident 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:

        1. You have a Visual Filter applied on the Card visual (on the Filters pane), or
        2. 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! 🙂

         

  • JarroVGIT's avatar
    JarroVGIT
    Resident Rockstar

    This is a calculated column and not a measure. Therefor, the ALLSELECTED is evaluated for each row in your table. If this is a measure, it would result in a syntax error because there is no context for (for example) MONTH('Quotes Estimates US'[Customer Created Date]). In a measure, that part would never evaluate on its own, but this might work in a calculated column. Are you sure this is a measure? âť“

    EDIT: This is a confirmed measure but used in different contexts.

     

    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! 🙂

    • Anonymous's avatar
      Anonymous
      Not applicable

      I created a new measure to create it and am using it in cards as shown below. But I need to add it to my matrix and when I do instead of the numbers adjusting by the salesperson they stay the same for all of the sales people. But when I filter the page by sales person the cards adjust. So what do I need to change? Taking out the all selected and just having all makes the numbers wrong.

       

  • v-kelly-msft's avatar
    v-kelly-msft
    Community Support

    Hi Anonymous ,

     

    If you wanna calculate in “customer status =A”, the related measure is as below:

     

     

    Measure = COUNTROWS(FILTER(SUMMARIZE(FILTER(ALLSELECTED('Quotes Estimates US'),'Quotes Estimates US'[Customer Status]="A"),'Quotes Estimates US'[Customer],"MinDate",FORMAT(MIN('Quotes Estimates US'[Customer Created Date]),"MMM YY")), [MinDate] in FILTERS(Calender[Month Year])))

     

     

     

    If you wanna calculate in all statuses, pls see below:

     

     

    Measure 2 = 
    var c = MAX('Quotes Estimates US'[Job Start Year])
    var prem = CALCULATE(MAX('Quotes Estimates US'[Job Start Year]),FILTER(ALLSELECTED('Quotes Estimates US'),'Quotes Estimates US'[Job Start Year]<c))
    var predis = CALCULATETABLE(DISTINCT('Quotes Estimates US'[Customer]),FILTER(ALLSELECTED('Quotes Estimates US'),'Quotes Estimates US'[Job Start Year] = prem),VALUES('Quotes Estimates US'[Customer Status]))
     
    return
    CALCULATE(DISTINCTCOUNT('Quotes Estimates US'[Customer]),FILTER('Quotes Estimates US',NOT('Quotes Estimates US'[Customer] in predis )))

     

     

    For the related .pbix file ,pls click here.

     

    Hope this would help.

     

    Best Regards,

    Kelly