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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Krcmajster
Helper IV
Helper IV

Count only values with most recent date

I am trying to get the count for pie chart where only latest values for specific account should be counted. I can get them but with creating table, however I want to do it with DAX only so I do not need to store the table. 

I was trying to use summarize, but I can't manage to use columns from virtual table to filter table

 

HealthDateAccount
Green01 April 2022Account1
Red01 March 2022Account1
Green01 April 2022Account2
Yellow01 May 2022Account2
Red01 February 2022Account3

 

 

DAXOnlyCount = 
var vTable =
SUMMARIZE ( ALL ( 'Table' ), 'Table'[Account], "Latest", MAX ( 'Table'[Date] ) )


return
CALCULATE(count('Table'[Health]),'Table'[Account]=vTable /*[Account] column*/,'Table'[Date]=vTable /*[Latest] column*/) //I get this is incorrect, I am just not sure how to do it. ))

 

 

Desired Output:

output.PNG

2 ACCEPTED SOLUTIONS

Thanks, but this only returns the latest value overall. I need latest value by each account. 
In case of Account1 that is Green, as date for it is Apr 01, for Account2 it is Yellow since it's on May 01 and for account 3 it is Red, only one value. 

View solution in original post

Anonymous
Not applicable

Hi @Krcmajster ,

You can create a measure as below to get it, please find the details in the attachment.

Count with most recent date = 
VAR _latestdate =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Account] ) )
RETURN 
    COUNTX (
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Account] ), 'Table'[Date] = _latestdate ),
        [Health]
    )

yingyinr_0-1650951161782.png

Best Regards

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Krcmajster , try if one of the two can help

 

DAXOnlyCount =
var vTable =
Maxx ( ALL ( 'Table' ), 'Table'[Date] )
return
CALCULATE(count('Table'[Health]), 'Table'[Date]=vTable /*[Latest] column*/)

 

or

 

DAXOnlyCount =
var vTable =
Maxx ( ALLexcept ( 'Table','Table'[Account] ), 'Table'[Date] )
return
CALCULATE(count('Table'[Health]), 'Table'[Date]=vTable /*[Latest] column*/)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks, but this only returns the latest value overall. I need latest value by each account. 
In case of Account1 that is Green, as date for it is Apr 01, for Account2 it is Yellow since it's on May 01 and for account 3 it is Red, only one value. 

Anonymous
Not applicable

Hi @Krcmajster ,

You can create a measure as below to get it, please find the details in the attachment.

Count with most recent date = 
VAR _latestdate =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Account] ) )
RETURN 
    COUNTX (
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Account] ), 'Table'[Date] = _latestdate ),
        [Health]
    )

yingyinr_0-1650951161782.png

Best Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.