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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DR2022
Helper I
Helper I

Grouping by ID and making difference between dates

Hi! I need help with a function. How can I get the difference between the previous FinishDate and the StartDate and after group by ID from the data table below? It can be in M ​​or DAX. The result would be in hours.

 

Imagem1.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Sorry allexcept does not work on this dax code

sue this instead

compareDate =
 
VAR startdate = Standby[Start Date]
var searchid = Standby[ID]
VAR maxfinishdate =
    CALCULATE (
        MAX ( Standby[End Date] ),
        FILTER ( ALL ( Standby ), Standby[End Date] < startdate&&Standby[ID]=searchid)
    )
VAR result =
    DATEDIFF ( startdate, maxfinishdate , DAY )
RETURN
    result

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

compareDate =
 
VAR startdate = Standby[Start Date]
VAR maxfinishdate =
    CALCULATE (
        MAX ( Standby[FinishDate] ),
        FILTER ( ALL ( Standby ), Standby[finishDate] < startdate,allexcept(Stanby,Stanby[ID])
    )
VAR result =
    DATEDIFF ( startdate, maxfinishdate , DAY )
RETURN
    result
Anonymous
Not applicable

Sorry allexcept does not work on this dax code

sue this instead

compareDate =
 
VAR startdate = Standby[Start Date]
var searchid = Standby[ID]
VAR maxfinishdate =
    CALCULATE (
        MAX ( Standby[End Date] ),
        FILTER ( ALL ( Standby ), Standby[End Date] < startdate&&Standby[ID]=searchid)
    )
VAR result =
    DATEDIFF ( startdate, maxfinishdate , DAY )
RETURN
    result
Anonymous
Not applicable

Hi Please find the code :

compareDate =
 
VAR startdate = Standby[Start Date]
VAR maxfinishdate =
    CALCULATE (
        MAX ( Standby[FinishDate] ),
        FILTER ( ALL ( Standby ), Standby[finishDate] < startdate )
    )
VAR result =
    DATEDIFF ( startdate, maxfinishdate , DAY )
RETURN
    result

It worked for the dates! But I think you have to create a variable to group by ID before making the difference between dates. Grouping dates by a, b, c, d. That's what I'm not able to do. And the result of your function is being a negative number

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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