Forum Discussion
Count specific values based on latest date
- 5 years ago
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,
KellyDid I answer your question? Mark my post as a solution!
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!
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-msft5 years agoCommunity 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))+0And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
- anin5 years agoFrequent Visitor
Hello v-kelly-msft ,
Thank you for your response and your help. It is very much appreciated!
I am getting closer, but not yet getting exactly the results I want.
The filter should not be set to exactly the defined _maxdate.
I want the count of all ID's where the entry is the closest equal/less than the defined _maxdate and Value1&2 = 2Perhaps this dataset and desired outcome explains it better:
If the selected day is 5th of february the highlighted entries are evaluated and the count is 2
If the selected day is 8th of february the highlighted entries are evaluated and the count is 1
Also I would like any other selected filters in the report page to remain selected for the card.
Here is a link to my dataset:
Once again thank you for your help!
Kind regards
- v-kelly-msft5 years agoCommunity Support
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,
KellyDid I answer your question? Mark my post as a solution!