Forum Discussion

Wegs's avatar
Wegs
New Member
6 years ago
Solved

Calculate DateDeff Between subsequent rows pending Sorting / Filters - Power Pivot

Hello,

 

New poster here but I have done some extensive research for a couple days now and having a hard time developing the DAX formula for calculating the time difference between one row and the subsequent rows.  I was using some of the content from this post to get a basic understanding but my issue is a bit more complicated:

 

https://community.powerbi.com/t5/Desktop/Based-on-Datetime-difference-between-current-row-and-previous/td-p/624227

 

I have order numbers

- These have many operations

 - These have many sub-operations

 

I want to filter on orders, sort on operations (and sub-operations), and determine the time difference from one sub-operation to the next. (Granted my real data set has 1000s of orders, some having 30 operations, and having 10 sub-operations for each operation).  I can do this via VBA no problem, but was hoping on a Power BI / Power Pivot solution

 

Here is a Sample Data Set:

 

Order NumberOperation NumberSub-Operation NumberTime StampResults
110102020-02-23null
110202020-02-241
120102020-02-262
210102020-01-30null
220102020-02-034
220202020-02-041

 

Let me know what you think.

 

 
  • Try

    date diff = datediff(table[timestamp] ,  maxx(filter(table,table[Order Number]=earlier(table[Order Number])
    										&& table[timestamp]< earlier(table[timestamp])),table[timestamp]),DAY)

2 Replies

  • Try

    date diff = datediff(table[timestamp] ,  maxx(filter(table,table[Order Number]=earlier(table[Order Number])
    										&& table[timestamp]< earlier(table[timestamp])),table[timestamp]),DAY)
    • Wegs's avatar
      Wegs
      New Member

      Excellent Work.  

       

      It seems to work quite well.  I have adjusted it to give me decimal numbers.

       

      Thanks for the quick response!