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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
GMelhouse
Frequent Visitor

Calculate Date Difference on two different rows

I have a table of help ticket data.  The create date/time on a critical outage is on one row and the Resolution date/time is on a different row of the table.  There are also rows for all activities that take place with the ticket.    I want to calculate the hours between the create date and the resolution for each ticket that is a critical outage.  It seems like I need to group by the ticket ID and then compare the dates, but I can't figure out the right formula to do that.  I also thought I could create a new table that would group by ticket ID, but that wasn't working for me either.  I'm new to PowerBI so any help would be appreciated.

 

So and example of my data is :

Ticket IDCreate DateEnd Date
1233/10/2017 3:07:23 AM 
123 3/10/2017 3:10:20 AM

 

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

Hi @GMelhouse,

 

You can refer to below formulas to achieve your requirement.

 

A. Write a measure or calculated column to calculate the diff.

Measure:

Diff = 
var ticketID=LASTNONBLANK(Table2[Ticket ID],[Ticket ID])
return
DATEDIFF(LOOKUPVALUE(Table2[Create Date],Table2[Ticket ID],ticketID),LOOKUPVALUE(Table2[Create Date],Table2[Ticket ID],ticketID),SECOND)

Calculate column:

DateDiff = DATEDIFF(LOOKUPVALUE('Table 2'[Create Date],'Table 2'[Ticket ID],[Ticket ID]),LOOKUPVALUE('Table 2'[End Date],'Table 2'[Ticket ID],[Ticket ID]),SECOND) 

12.PNG

 

B. Summary table and get the diff.

Result = ADDCOLUMNS(SUMMARIZE(Table,[Ticket ID],"Create Date",MAX(Table[Create Date]),"End Date",MAX(Table[End Date])),"Diff",DATEDIFF([Create Date],[End Date],SECOND))

11.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @GMelhouse,

 

You can refer to below formulas to achieve your requirement.

 

A. Write a measure or calculated column to calculate the diff.

Measure:

Diff = 
var ticketID=LASTNONBLANK(Table2[Ticket ID],[Ticket ID])
return
DATEDIFF(LOOKUPVALUE(Table2[Create Date],Table2[Ticket ID],ticketID),LOOKUPVALUE(Table2[Create Date],Table2[Ticket ID],ticketID),SECOND)

Calculate column:

DateDiff = DATEDIFF(LOOKUPVALUE('Table 2'[Create Date],'Table 2'[Ticket ID],[Ticket ID]),LOOKUPVALUE('Table 2'[End Date],'Table 2'[Ticket ID],[Ticket ID]),SECOND) 

12.PNG

 

B. Summary table and get the diff.

Result = ADDCOLUMNS(SUMMARIZE(Table,[Ticket ID],"Create Date",MAX(Table[Create Date]),"End Date",MAX(Table[End Date])),"Diff",DATEDIFF([Create Date],[End Date],SECOND))

11.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks for your help.  The third one worked for me.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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