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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
SushmaReddy
Helper I
Helper I

Count Distinct from latest records

Max Date =
Var mat= T1[Mat1]
return
MAXX(
FILTER(ALL(T1),T1[M1]=mat),(T1[Date]))     to get max date records
Another Column to get the count of failed records
# Error = IF(And(T1[Date]=T1[Max Date],Single_Material[Status]="Failed"),1,0)
Here comes the problem where i have duplicates for failed records as shown below.
M1    Date                         Status
123   02-02-2022             Failed
123   02-02-2022             Failed
231   02-02-2022             Failed
456   02-02-2022             Failed
456   03-02-2022             Success
I am getting the failed count as 2 but i want it as 2.If the latest record is failed it should not be counted.
2 ACCEPTED SOLUTIONS
v-chenwuz-msft
Community Support
Community Support

Hi @SushmaReddy ,

 

You can try this code:

Measure =
VAR _s =
    SUMMARIZE (
        'Table',
        [M1],
        "max", MAX ( 'Table'[Date] ),
        "status",
            CALCULATE (
                MAX ( 'Table'[Status] ),
                FILTER ( 'Table', 'Table'[M1] = EARLIER ( 'Table'[M1] ) )
            )
    )
RETURN
    COUNTROWS ( FILTER ( _s, [status] = "Failed" ) )

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

Thank you and the logic is working

View solution in original post

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi @SushmaReddy ,

 

You can try this code:

Measure =
VAR _s =
    SUMMARIZE (
        'Table',
        [M1],
        "max", MAX ( 'Table'[Date] ),
        "status",
            CALCULATE (
                MAX ( 'Table'[Status] ),
                FILTER ( 'Table', 'Table'[M1] = EARLIER ( 'Table'[M1] ) )
            )
    )
RETURN
    COUNTROWS ( FILTER ( _s, [status] = "Failed" ) )

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you and the logic is working

amitchandak
Super User
Super User

@SushmaReddy , try like

 

Measure =
VAR __id = MAX ('Table'[M1] )
VAR __date = CALCULATE ( MAX('Table'[Date] ), ALLSELECTED ('Table' ), 'Table'[M1] = __id )
CALCULATE ( Count ('Table'[Status] ), VALUES ('Table'[M1] ),'Table'[M1] = __id,'Table'[Date] = __date, 'Table'[Status] = "Failed" )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.