Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
SAU1111
Frequent Visitor

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.

SAU1111_0-1661912611213.png

 

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @SAU1111 ,

 

Please add an index column in Power Query:

vyadongfmsft_0-1662372473021.png

 

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)

vyadongfmsft_1-1662372821823.png

 

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.

 

View solution in original post

3 REPLIES 3
v-yadongf-msft
Community Support
Community Support

Hi @SAU1111 ,

 

Please add an index column in Power Query:

vyadongfmsft_0-1662372473021.png

 

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)

vyadongfmsft_1-1662372821823.png

 

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.

 

amitchandak
Super User
Super User

@SAU1111 , 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)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I think its not working could you confirm :

 

SAU1111_0-1661939616724.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.