Forum Discussion
Time Difference
Hi All,
I got an issue and even going through most of Time Blogs can't get my brain ticking...
I got this data where dateTime is one field and SKU is other. I want to find how long a SKU takes to change on a given date (time). Some days SKU will be running for 5 days but what I am interested is when it change from one SKU to other whats the time difference .
Thanks
5 Replies
- jaideepnemaSolution Sage
Hi Anonymous ,
Can you please share a sample dataset to check this further ?Regards,
Jaideep
- AnonymousNot applicable
I did in the problem. do you need the excel file ?
- colacanResolver II
Anonymous Hi sahwal,
Let's say your table is as below,
DateTime_ PO Line_id SKU 2021-01-01 1234 1 170448 2021-01-02 1234 1 170448 2021-01-03 1234 1 170448 2021-01-04 1234 1 170448 2021-01-05 1234 1 180111 2021-01-06 1234 1 180111 2021-01-07 1234 1 180111 2021-01-08 1234 1 200100 2021-01-09 1234 1 300100 To get the time period for each SKU you can try below measure;
TimePerSKU =VAR CurrentSKU = MAX( SKU_Time[SKU] )VAR SelectedSKU = FILTER( SKU_Time, SKU_Time[SKU] = currentSKU )VAR Result =DATEDIFF(FIRSTNONBLANK( SKU_Time[DateTime_], SKU_Time[DateTime_] ),LASTNONBLANK( SKU_Time[DateTime_], SKU_Time[DateTime_] ),HOUR)RETURN INT( DIVIDE( result, 24 ) ) & " Days "& MOD( result, 24 ) & "hours"I hope this helps you.
If you like my answer please select this as the solution and Kudo.
Thanks!
- AnonymousNot applicable
HI Colacan
Looks good but what its doing is giving me total hours a SKU run in a day or year what I was looking for eg
SKU datetime
109328 30/08/2021 3:17 am
112111 30/08/2021 6:15am
156674 02/09/2021 1:00Pm
Now when in Maufacturing we did chnage from lets say 109328 to 112111 it should tell me time it took to do changeover (6:15-3:17 )am=x hours
- ERDCommunity Champion
Hi Anonymous ,
As a general advise, please, provide data sample in a table format (not as an image) and an example of the expected result. How to Get Your Question Answered Quickly
If you expect to have this result
you can try the measure below:
diff_h = VAR c_sku = SELECTEDVALUE ( T[SKU] ) VAR minDate = MINX ( FILTER ( ALL ( T[DateTime_], T[SKU] ), T[SKU] = c_sku ), T[DateTime_] ) VAR c_date = SELECTEDVALUE ( T[DateTime_] ) VAR prevDate = CALCULATE ( MAX ( T[DateTime_] ), FILTER ( ALLSELECTED ( T ), T[DateTime_] < c_date ) ) VAR difference = DATEDIFF ( prevDate, c_date, HOUR ) RETURN IF ( c_date = minDate && NOT ( ISBLANK ( prevDate ) ), difference, BLANK () )If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.