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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
SBrooky
New Member

DateDiff from two dates in same row

I need to calculate the datedifference between two dates in the same column. I cant seem to find an answer for this and would like to learn how to do this in PowerBi instead of excel.

 

Where the event type is 1, I need a new column at the end that finds the next time the same ResourceID has the EventType of 0

 https://prnt.sc/p7oxg3 

 

Ive looked at doing a datediff with the end date using a filter with calculate but cant seem to get this to work in any way. I think I just need to wrap my head around this to get my head out of Excel ways and into PowerBi.

1 ACCEPTED SOLUTION
AnthonyTilley
Solution Sage
Solution Sage

try this 

 

Column = 
-- first get the event type, resource and time of the current rows event 
Var eventType = 'Table'[EventType]
var rID = 'Table'[ResourceID]
var cur = 'Table'[EventTime]
-- calculate the min date for the table when resource is equal to the current resource, the event is 0 and its greater than the current date var nextevent = CALCULATE(min('Table'[EventTime]),all('Table'),'Table'[ResourceID] = rid, 'Table'[EventTime] > cur, 'Table'[EventType] = 0)
--apply the value to oonly event type 1 Var ret = if(eventType = 0 , blank(), nextevent)
-- return the value return ret

example 

event id.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
AnthonyTilley
Solution Sage
Solution Sage

try this 

 

Column = 
-- first get the event type, resource and time of the current rows event 
Var eventType = 'Table'[EventType]
var rID = 'Table'[ResourceID]
var cur = 'Table'[EventTime]
-- calculate the min date for the table when resource is equal to the current resource, the event is 0 and its greater than the current date var nextevent = CALCULATE(min('Table'[EventTime]),all('Table'),'Table'[ResourceID] = rid, 'Table'[EventTime] > cur, 'Table'[EventType] = 0)
--apply the value to oonly event type 1 Var ret = if(eventType = 0 , blank(), nextevent)
-- return the value return ret

example 

event id.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Excellent works perfectly and i've figured out how it works too, didnt realise you could do so much in a column. Thank you for your help!

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Kudoed Authors