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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

How to count number of elements but only when it's the last state

Hi everyone, 

 

I'd like to show a number which is a count but only when the update_date is the latest.

Example :

here is my dataset :

IDUpdate_date

Status

101/01/2020

1

102/01/2020

1

103/01/2020

0

201/01/2020

0

202/01/2020

1

301/01/2020

0

302/01/2020

0

303/01/2020

0

304/01/2020

1

 

I'd like to display the number of each last status but only once per ID, so for the number of "1" status, if the current date is 05/01/2020, I should read "2".

And for the number of "0" status, if the current date is 05/01/2020, I should read "1".

 

Could you help me please?

 

Thank you.

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a measure to meet your requirement:

 

 

Count of Last Date = 
VAR t =
    FILTERS ( 'Table'[Status] )
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                ALLSELECTED ( 'Table' ),
                'Table'[ID],
                "LastStatus",
                VAR m =
                    CALCULATE (
                        MAX ( 'Table'[Update_date] ),
                        FILTER (
                            'Table' ,
                            'Table'[Update_date] <= MAX ( 'calendar'[Date] )
                        )
                    )
                RETURN
                    CALCULATE (
                        COUNTROWS ( 'Table' ),
                        FILTER ( 'Table', 'Table'[Update_date] = m && 'Table'[Status] IN t )
                    )
            ),
            [LastStatus] <> 0
        )
    )

 

 

13.jpg


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a measure to meet your requirement:

 

 

Count of Last Date = 
VAR t =
    FILTERS ( 'Table'[Status] )
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                ALLSELECTED ( 'Table' ),
                'Table'[ID],
                "LastStatus",
                VAR m =
                    CALCULATE (
                        MAX ( 'Table'[Update_date] ),
                        FILTER (
                            'Table' ,
                            'Table'[Update_date] <= MAX ( 'calendar'[Date] )
                        )
                    )
                RETURN
                    CALCULATE (
                        COUNTROWS ( 'Table' ),
                        FILTER ( 'Table', 'Table'[Update_date] = m && 'Table'[Status] IN t )
                    )
            ),
            [LastStatus] <> 0
        )
    )

 

 

13.jpg


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.

Top Solution Authors
Top Kudoed Authors