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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
RichardJ
Responsive Resident
Responsive Resident

Finding a value in a column, navigating to the next change in value, then perform calculation

Hi,

I've been trying without success (so far!) to calculate the machine downtime from the available data

 

The 'Status' of "NC Stop" means the machine has stopped at the time stated in the 'Date' column

The 'Status' of "NC Start" means the machine has started at the time stated in the 'Date' column

 

Thanks to some earlier help from from @JarroVGIT Calculating Machine uptime - is this possible in Power BI from the data available?

I was able to calculate the 'Time of next log entry event'/create an index/understand a good approach which was great however, having received more complete data the fact that there can be multiple 'NC Start' statuses has muddied the waters.

 

The part which is confusing me is that there can be multiple "NC Start" entries in the 'Status' column as the machine works its way through the different operations.

 

In the table below I would like to find:

 

Machine Stopped Time = Find the next row with a 'Status' of 'NC Stop' and note the Date value
Machine Started Time = From the row which was found, find the first next occurence of a row with a Status of 'NC Start' and note the Date Value
Machine Downtime = Machine Started Time - Machine Stopped Time
 
Please ignore the Total Idle Time and Time Difference columns - they are only there as I've been playing around.
 
The current formulas are:
Next Status Change Time = CALCULATE(MIN('OMV 1'[Date]), FILTER('OMV 1', 'OMV 1'[Status] <> EARLIER('OMV 1'[Status]) && 'OMV 1'[Date] > EARLIER('OMV 1'[Date])))
Time Difference (Seconds) = DATEDIFF('OMV 1'[Date], 'OMV 1'[Next Status Change Time], SECOND)
 

Am guessing that the 'Next Status Change Time' formula needs to change to find a later rather than earlier value. Have tried playing about with the parameters without success.

 

Any help or advice would be appreciated.

 

Thanks

 

DateTypeOperationTextAttributesStatusStop ReasonIndexNext Status Change TimeTime Difference (Seconds)Time Difference (Minutes)Time of next log entry eventTime since last log entry (Second)Total Idle Time
24/09/2019 04:37Key  0x01F0 -> NC StartNC Start 024/09/2019 07:06890014924/09/2019 04:3711491688
24/09/2019 04:37Key  0x01F0 -> NC StartNC Start 124/09/2019 07:06889914924/09/2019 04:39841491688
24/09/2019 04:39Key  0x01F0 -> NC StartNC Start 224/09/2019 07:06881514724/09/2019 04:3911491688
24/09/2019 04:39Key  0x01F0 -> NC StartNC Start 324/09/2019 07:06881414724/09/2019 06:0451121491688
24/09/2019 06:04Key  0x01F0 -> NC StartNC Start 424/09/2019 07:0637026224/09/2019 06:0411491688
24/09/2019 06:04Key  0x01F0 -> NC StartNC Start 524/09/2019 07:0637026224/09/2019 06:0411491688
24/09/2019 06:04Key  0x01F0 -> NC StartNC Start 624/09/2019 07:0637026224/09/2019 06:0411491688
24/09/2019 06:04Key  0x01F0 -> NC StartNC Start 724/09/2019 07:0637026224/09/2019 06:0411491688
24/09/2019 06:04Key  0x01F0 -> NC StartNC Start 824/09/2019 07:0637016224/09/2019 06:5832381491688
24/09/2019 06:58Key  0x01F0 -> NC StartNC Start 924/09/2019 07:06463824/09/2019 07:064631491688
24/09/2019 07:06Info  MAINNC StopM021024/09/2019 07:176581124/09/2019 07:176581491688
24/09/2019 07:17Key  0x01F0 -> NC StartNC Start 1124/09/2019 09:59973816224/09/2019 07:18881491688
24/09/2019 07:17Key  0x01F0 -> NC StartNC Start 1224/09/2019 09:59973816224/09/2019 07:18881491688
24/09/2019 07:18KeyOP20 0x01F0 -> NC StartNC Start 1324/09/2019 09:59965016124/09/2019 08:4149481491688
1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @RichardJ ,

 

You can create columns like DAX below.

 

 

Machine Stopped Time= CALCULATE(MIN('OMV 1'[Date]), FILTER('OMV 1', 'OMV 1'[Status] ="NC Stop" && 'OMV 1'[Index] > EARLIER('OMV 1'[Index])))
 
Machine Started Time = CALCULATE(MIN('OMV 1'[Date]), FILTER('OMV 1', 'OMV 1'[Status] ="NC Start" && 'OMV 1'[Index] > EARLIER('OMV 1'[Index])))
 
Machine Downtime = [Machine Started Time] - [Machine Stopped Time]

 

 

Best Regards,

Amy

 

Community Support Team _ Amy

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

2 REPLIES 2
v-xicai
Community Support
Community Support

Hi @RichardJ ,

 

You can create columns like DAX below.

 

 

Machine Stopped Time= CALCULATE(MIN('OMV 1'[Date]), FILTER('OMV 1', 'OMV 1'[Status] ="NC Stop" && 'OMV 1'[Index] > EARLIER('OMV 1'[Index])))
 
Machine Started Time = CALCULATE(MIN('OMV 1'[Date]), FILTER('OMV 1', 'OMV 1'[Status] ="NC Start" && 'OMV 1'[Index] > EARLIER('OMV 1'[Index])))
 
Machine Downtime = [Machine Started Time] - [Machine Stopped Time]

 

 

Best Regards,

Amy

 

Community Support Team _ Amy

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

RichardJ
Responsive Resident
Responsive Resident

Appreciate you pointing me in the right direction @v-xicai  - Thank you

 

Applied a filter to only select 'Status' of "NC Stop" (This is where I was going wrong as having superflous data in the table was confusing matters when calculating the time difference between row/events)

 

This column was added

Time of next NC Start entry = CALCULATE(MIN('OMV 1'[Date]), FILTER('OMV 1', 'OMV 1'[Status] <> EARLIER('OMV 1'[Status]) && 'OMV 1'[Date] > EARLIER('OMV 1'[Date])))
 
to find the Start time following the previous Stop.
 
The time difference between the NC Stop and the NC Start was found using this
Machine Idle Time (Minutes) = DATEDIFF( 'OMV 1'[Date],'OMV 1'[Time of next NC Start entry], MINUTE)
 
This provided me with the duration of how long the machine wasn't working which is what I was after.
 
Thanks again!
 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors