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
Anonymous
Not applicable

Time Difference

Hi All,

 

I got an issue and even going through most of Time Blogs can't get my brain ticking...

sahwal_77_0-1632638091155.png

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 5
ERD
Super User
Super User

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

ERD_0-1632731282172.png

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.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

colacan
Resolver II
Resolver II

@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"
 
colacan_0-1632690479401.png

 

I hope this helps you.

If you like my answer please select this as the solution and Kudo.

Thanks!

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 

jaideepnema
Solution Sage
Solution Sage

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

 

Regards,

Jaideep

Anonymous
Not applicable

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

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.