Calculation of duration of running state of machine

Hello Everyone, I have my app on Mindsphere using Mendix. I am able to receive time series data in graph.  Now I want to calculate the duration from which my machine is in running state (i.e. 1) till it is in idle state(i.e. 0). How can I do this calculation? Please help.  
1 answers

I guess millisecondsBetween won’t cut it. Can you give some more information, some screenshots etc. since most of us on this forum have no access to a Mindsphere app.