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
mcc
Frequent Visitor

Datediff ROWS - 1 order, 8 steps. 3 critical columns: order #, date/time, step name

This data is interfaced with an app and is returned as the below:

 

Woe_orderno is the order #.  I have over 20,000 orders.  I want to build a matrix that shows each order and the time it took for each step in the StampType column.  StampType column is a related table based on the woe_activitytype. 

 

I’m trying to show the time it took from Start Pump to Stop Pump, then Stop Pump to Call Surveyor, etc.

I have tried unpivoting woe_activitytype and Start Time and it just returns a new column with attributes and the same data format.  

What am I missing?

 

mcc_0-1665423092966.png

 

1 ACCEPTED SOLUTION
mcc
Frequent Visitor

This is resolved.  It was correct to pivot, but I was "unpivoting" when I should have first "pivoted" then "unpivoted."  That solved my layout and I could write the measures for the datedif (as they were not in sequence).  Thank you all.  

View solution in original post

4 REPLIES 4
mcc
Frequent Visitor

This is resolved.  It was correct to pivot, but I was "unpivoting" when I should have first "pivoted" then "unpivoted."  That solved my layout and I could write the measures for the datedif (as they were not in sequence).  Thank you all.  

v-yiruan-msft
Community Support
Community Support

Hi @mcc ,

In order to give you a suitable solution quickly, could you please provide some raw data(exclude sensitive data) in the order table with Text format? And share the order of every steps? What's your expected result? Do you want to get the time duration for every step in Power Query? If yes, you can refer the following link to get it... 

1. Start Pump

2. Stop Pump

3. Call Surveyor

...

time difference between 2 rows

yingyinr_0-1665472478596.png

In addition, we can consider to achieve it by DAX. Please refer the following link to get it.

Calculate the difference between 2 rows in PowerBI using DAX

Find difference between two rows by usind Dax in Power BI

yingyinr_1-1665472804321.png

Difference between two rows

Column =
VAR NextIndex = Table1[Index] + 1
RETURN
    Table1[Orders]
        - CALCULATE (
            VALUES ( Table1[Orders] ),
            FILTER ( ALL ( Table1 ), Table1[Index] = NextIndex )
        )

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for offering your suggestion. It is a very good one; however, the times stamps are not in sequence.  I did resolve the issue though...I was "unpivoting" when I should have first "pivoted" then "unpivoted."  That solved my layout and I could write the measures for the datedif (as they were not in sequence).  Thank you all.  

Thank you for information.  I should note, the calculations I need are not insequence.  So, index will not work, as I am not using one stamp to the next.  It is specific stamps.  The expected results is that I can create any time difference between any 2 stamps.  But they are not in sequence.  It can be the 1st and 5th stamps or the 2nd and 6th.  Every variation.  

 

 

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.