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

Time calculation based on second row

Hello,

I have around 10 machines in my shop. I need to know the total ammount of time the machines are running (need to know the down times). I have a column called "EnFonction". Basically all I need to know is the total ammount of time the value of "EnFonction" is "True".

 

In the table below, the total ammount of time would be:

(11:43:34-11:42:35) + (12:00:58-12:00:25).

In other words, my machine was down from 11:43:34 to 12:00:25.

 

The example below is somewhat simple as it is for only one machine. I guess I need to be able to do this math with one machine at first.

But as you can see the table is filtered on the column BonTravail (Work Order). There will be many other lines and my aim is to seperate every calculation based on the work order.

 

I could format the table differently: that table is created from a PLC I programmed myself so I have some freedom on that part.

 

Could someone help me with that?

I searched for a whole day but was not able to find a similar application.

Thanks!

 

mstsc_6Cuds05hEI.png

1 ACCEPTED SOLUTION
sTaLa
Frequent Visitor

I received help from Microsoft support team. I am really impressed with the quality of the service I received! Here's what Thanmayee came up with to help me.

 

First, create two new columns of Timestamps. These are filtered columns: one of them only contains timestamps where EnFonction was True; the other column only contains timestamps where EnFonction was False.

 

Then create a calculated column where that DAX syntax:

 

uptime(sec) = 
VAR temp =
    TOPN (
        1;
        FILTER (
            MachineRunning;
            MachineRunning[ID] = EARLIER (MachineRunning[ID])
                && MachineRunning[TimeTrue] < EARLIER (MachineRunning[TimeTrue])
        );
        [Timestamp]; DESC
    )
RETURN IF(MachineRunning[EnFunction]=FALSE(); 0;(DATEDIFF ( MINX ( temp; MachineRunning[TimeTrue]); MachineRunning[TimeTrue]; SECOND)))

 

In the example below, all the values are filter on column ID. This ID serves as a WorkOrder number instead of the NoBonTravail column I used in my OP.

 

WINWORD_3783rP0APu.png

View solution in original post

5 REPLIES 5
sTaLa
Frequent Visitor

Alright, I did some more work on it and I think I established a good strategy. I need to create a new table based on the initial table. That new table would have one column for the StartTime, and another for the StopTime. This would allow me to easily calculate the running time with DATEDIFF.

 

The definition of the StartTime would be:

---- For a specified machine,

       ----the first row where EnFonction = True after it was False.

The definition of StopTime would be:
---- For a specified machine,

      ---- after the last StartTime,

             ---- the last row where EnFonction = True

 

Then I could use that post to calculate my UpTime:

Mean Time Between Failure (MTBF) and Power BI 

 

Now I need to figure out the DAX to create my new table.

Based on the sample I shoed on December 11th, the newly created table will need to look like this one.

 

EXCEL_sB9Lt11Gyn.png

sTaLa
Frequent Visitor

I received help from Microsoft support team. I am really impressed with the quality of the service I received! Here's what Thanmayee came up with to help me.

 

First, create two new columns of Timestamps. These are filtered columns: one of them only contains timestamps where EnFonction was True; the other column only contains timestamps where EnFonction was False.

 

Then create a calculated column where that DAX syntax:

 

uptime(sec) = 
VAR temp =
    TOPN (
        1;
        FILTER (
            MachineRunning;
            MachineRunning[ID] = EARLIER (MachineRunning[ID])
                && MachineRunning[TimeTrue] < EARLIER (MachineRunning[TimeTrue])
        );
        [Timestamp]; DESC
    )
RETURN IF(MachineRunning[EnFunction]=FALSE(); 0;(DATEDIFF ( MINX ( temp; MachineRunning[TimeTrue]); MachineRunning[TimeTrue]; SECOND)))

 

In the example below, all the values are filter on column ID. This ID serves as a WorkOrder number instead of the NoBonTravail column I used in my OP.

 

WINWORD_3783rP0APu.png

Hi @sTaLa ,


Glad to hear that you have resolved your problem. Thank you for sharing this wonderful solution, we have learned a lot from it.

 

Would you please kindly mark your shared solution as an answer so that it can benefit more users?


Best regards,

 

Community Support Team _ Dong Li
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

 If possible please share a sample pbix file after removing sensitive information.
Thanks

Sure!

See to that link: Prod_DB_BI_(local)_07 Share 

Thanks for your help!

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.