Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

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

  • Hi Anonymous ,
    Can you please share a sample dataset to check this further ?

     

    Regards,

    Jaideep

    • Anonymous's avatar
      Anonymous
      Not applicable

      I did in the problem. do you need the excel file ?

  • Anonymous  Hi sahwal,

    Let's say your table is as below,

    DateTime_POLine_idSKU
    2021-01-0112341170448
    2021-01-0212341170448
    2021-01-0312341170448
    2021-01-0412341170448
    2021-01-0512341180111
    2021-01-0612341180111
    2021-01-0712341180111
    2021-01-0812341200100
    2021-01-0912341300100

     

    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!

    • Anonymous's avatar
      Anonymous
      Not 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 

  • ERD's avatar
    ERD
    Community 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.