The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I want to calculate the time spent between two steps with the same id in a new column.
What I mean, is that even though in time after doc_id 1; step_id 4 it comes doc_id 2; step_id 2, but I want to calculate the time difference between doc_id 1;step 4 and doc_id1; step 5.
every doc_id can start with a random step_id, but it is sequential after
DOC_ID | STEP_ID | START_DATE | END_DATE |
1 | 4 | 1/24/2019 1:43:47 PM | 1/24/2019 1:43:48 PM |
2 | 2 | 1/24/2019 1:43:49 PM | 1/24/2019 1:43:50 PM |
1 | 5 | 1/24/2019 1:48:42 PM | 1/24/2019 1:48:43 PM |
2 | 3 | 1/24/2019 1:48:43 PM | 1/24/2019 1:48:43 PM |
3 | 4 | 1/24/2019 1:51:49 PM | 1/24/2019 1:51:49 PM |
2 | 4 | 1/24/2019 1:51:50 PM | 1/24/2019 1:51:52 PM |
1 | 6 | 1/25/2019 9:11:12 PM | 1/25/2019 9:11:12 PM |
3 | 5 | 1/25/2019 9:11:28 PM | 1/25/2019 9:11:28 PM |
Like this?
_SD =
var _doc = SELECTEDVALUE('Table'[DOC_ID];"Multiple")
var _sd = SELECTEDVALUE('Table'[START_DATE])
return
DATEDIFF(
CALCULATE(MAX('Table'[END_DATE]);FILTER(ALL('Table');'Table'[DOC_ID]=_doc && 'Table'[START_DATE] < _sd))
; MIN('Table'[START_DATE]);MINUTE)
as seen here:
File available here.
Pls mark as solution if it works for you. Thumbs up for the effort is appreciated.
Kind regards, Steve.
Proud to be a Super User!
Awesome Keyboard Shortcusts in Power BI, thumbs up if you like the article
My Community Blog Articles (check them out!)
My Blog - Power M code to automatically detect column types -
How to create test data using DAX!