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
Ecan20
Frequent Visitor

DAX to compute the difference between date for specific items

Dear experts,
I have a table like the example below with product ID, StartDate, EndDate. I would like to calculate the difference between the last EndDate and the first StartDate per each iem ID, like shown in the DateDiff column. Is that possible with a measure? Appreciate if you can offer some help. 

 

TIA!

 

IDStartDateEndDateDateDiff
121-12-11 22:3021-12-11 23:470.04167
121-12-11 23:4721-12-11 23:300.04167
221-12-11 23:5722-12-11 0:000.01250
222-12-11 0:0022-12-11 0:140.01250
222-12-11 0:1422-12-11 0:150.01250
322-12-11 0:2722-12-11 0:400.02569
322-12-11 0:4022-12-11 0:550.02569
322-12-11 0:5522-12-11 1:040.02569
422-12-11 1:0622-12-11 1:570.04514
422-12-11 1:5722-12-11 2:030.04514
422-12-11 2:0322-12-11 2:110.04514
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this column expression and convert the column to type decimal.

 

NewColumn =
VAR thisID = IDs[ID]
VAR minDT =
    MINX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[StartDate] )
VAR maxDT =
    MAXX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[EndDate] )
RETURN
    maxDT - minDT

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this column expression and convert the column to type decimal.

 

NewColumn =
VAR thisID = IDs[ID]
VAR minDT =
    MINX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[StartDate] )
VAR maxDT =
    MAXX ( FILTER ( IDs, IDs[ID] = thisID ), IDs[EndDate] )
RETURN
    maxDT - minDT

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@Ecan20 

 

Are you sure you want a measure and not a calculated column? What should a measure return if there are many different ID's visible in the current context? Your picture suggests that you want a calculated column...

@Anonymous you are right, a calculated column will work better for my case. I am not really familiar though, could you help me through the steps please? Thank you

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.