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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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