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
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
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.