Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Days Difference between work order previous open date and last work order closed date

Hi All,

 

I have a query as i have a table where i wish to create a difference between the same serial number's first Work order closed and second Work order opened date as Days Diff so that i can find out when the next work order was created after the previous one was closed . Please support .  Below is the list of details.  i have lots of serial numbers and Work order none in a sequence but randoms.

 

  • Hi Anonymous ,

     

    Please add an index column in Power Query:

     

    Then please try following DAX:

    Days difference = 
    var cur_index = 'Table'[Index]
    var pre_index = cur_index+1
    var diffe = CALCULATE(
        MAX('Table'[CreateDate]),
        FILTER('Table','Table'[Index] = pre_index && 'Table'[Serial Number] = EARLIER('Table'[Serial Number])))
    return
    DATEDIFF([ClosedOn],diffe,DAY)

     

    If I misunderstand your demands, please feel free to contact us in time.

     

    Best regards,

    Yadong Fang

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

     

3 Replies

  • Anonymous , a new column

     

     Datediff( [Close Date], Minx(filter(Table, [Serial Number]= earlier([Searial Number]) && [Open Date] > earlier([Close date]) ) , [Open Date]) , Day)

     

    or

    Datediff( [Close Date], Minx(filter(Table, [Serial Number]= earlier([Searial Number]) && [Open Date] > earlier([Open date]) ) , [Open Date]) , Day)

    • Anonymous's avatar
      Anonymous
      Not applicable

      I think its not working could you confirm :

       

       

  • v-yadongf-msft's avatar
    v-yadongf-msft
    Community Support

    Hi Anonymous ,

     

    Please add an index column in Power Query:

     

    Then please try following DAX:

    Days difference = 
    var cur_index = 'Table'[Index]
    var pre_index = cur_index+1
    var diffe = CALCULATE(
        MAX('Table'[CreateDate]),
        FILTER('Table','Table'[Index] = pre_index && 'Table'[Serial Number] = EARLIER('Table'[Serial Number])))
    return
    DATEDIFF([ClosedOn],diffe,DAY)

     

    If I misunderstand your demands, please feel free to contact us in time.

     

    Best regards,

    Yadong Fang

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