Forum Discussion

anin's avatar
anin
Frequent Visitor
5 years ago
Solved

Count specific values based on latest date

Hello,

 

I would like to count data entries with a specific value based on latest selected less than or equal date and have created a date table with a separate slider in my report.

 

This is my data set:

 

 

In my report I would like a card visualisation to count the number of different ID's with value1 and value 2 being equal to the number "2", that are closest less than or equal to the selected date.

 

For instance if the selected day is 2. january the count would be 3. If the selected day is 6. January the count would be 2 and if the selected day is 10. january the count would be 1.

 

Can someone help me how to acomplish this?

 

Thanks in advance

  • Hi  anin ,

     

    Modify the measure as below:

     

    Measure = 
    var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER(ALLSELECTED('Table'),'Table'[Date]<=SELECTEDVALUE('calendar table'[Date])&&'Table'[ID]=MAX('Table'[ID])))
    var _tab=SUMMARIZE('Table','Table'[ID],'Table'[Date],"value",IF(MAX('Table'[Date])=_maxdate&&MAX('Table'[Value1])=2&&MAX('Table'[Value2])=2,1,BLANK()))
    Return
    SUMX(_tab,[value])
    sum = SUMX(VALUES('Table'[ID]),[Measure])

     

    And you will see:

    For the related .pbix file,pls see attached.

     

    Best Regards,
    Kelly

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

6 Replies

  • anin , Try a measure like. I have not tested this

     

    measure =
    Var _1 = calculateTable(all(Table), Table[Date] <=selectedvalue(Table[Date]))
    return
    counrows(distinct(union(all(_1[value1]), all(_1[value2]))))

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

    Hi  anin ,

     

    Sorry I'm a little confused about your expected output,you said if the selected date is Jan2,then the count should be 1,if the selected date is Jan1,the count should be 2,why?For Jan2,values for ID 1,2,3 both have number 2,so why the count is 1,not 3?

     

    Best Regards,
    Kelly

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

    • anin's avatar
      anin
      Frequent Visitor

      Hi v-kelly-msft ,

       

      Sorry, there was an error in my expected output! I understand the confusion.

      This is my expected outcome:

       

      If the selected day is 2. january the count would be 3. If the selected day is 6. January the count would be 2 and if the selected day is 10. january the count would be 1. If the selected day is 1. january it should show 0.

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

        Hi anin ,

         

        First create a calendar table;

        Then create a measure as below:

        Measure = 
        var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Date]<=SELECTEDVALUE('calendar table'[Date])&&'Table'[ID]=MAX('Table'[ID])))
        Return
        CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Value1]=2&&'Table'[Value2]=2&&'Table'[Date]=_maxdate))+0

        And you will see:

        For the related .pbix file,pls see attached.

         

        Best Regards,
        Kelly

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