Forum Discussion
Display activities durations using Power BI
Hi,
I am using power bi in a manufacturing environment.
As part of it I would like to monitor the durations that some system was On and the duration it was Off.
This system logging events of Start and Stop with the timestamp.
I have this data in specific table (the fields are timestamp & event)
Duration between Start to Stop is the diff between the Stop Timestamp to the Start one and this is the duration system was On.
Duration between Stop to next Start is the diff between the Start Timestamp to the Stop one and this is the duration system was Off.
I also have Date & Time dimension table.
Could someone please propose me how to display in a visual the durations that system was on and off ? and also how to configure relationship in the model ?
Thank you
Hi Ofire ,
Assumed that your data is the same structure as the sample below:
Then you can use the following two measure:
Onduration = VAR Duration = SUMX ( 'Table', IF ( 'Table'[event] = "start", VAR a = 'Table'[Timestap] VAR b = CALCULATE ( MIN ( 'Table'[Timestap] ), FILTER ( 'Table', 'Table'[Timestap] >= a && 'Table'[event] = "stop" ) ) RETURN DATEDIFF ( a, b, SECOND ), 0 ) ) VAR Hours = INT ( Duration / 3600 ) VAR Minutes = INT ( MOD ( Duration, 3600 ) / 60 ) VAR Seconds = MOD ( MOD ( Duration, 3600 ), 60 ) VAR H = IF ( LEN ( Hours ) = 1, CONCATENATE ( "0", Hours ), CONCATENATE ( "", Hours ) ) VAR M = IF ( LEN ( Minutes ) = 1, CONCATENATE ( "0", Minutes ), CONCATENATE ( "", Minutes ) ) VAR S = IF ( LEN ( Seconds ) = 1, CONCATENATE ( "0", Seconds ), CONCATENATE ( "", Seconds ) ) RETURN CONCATENATE ( H, CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) ) Offduration = VAR Duration = SUMX ( 'Table', IF ( 'Table'[event] = "stop", VAR a = 'Table'[Timestap] VAR b = CALCULATE ( MIN ( 'Table'[Timestap] ), FILTER ( 'Table', 'Table'[Timestap] >= a && 'Table'[event] = "start" ) ) RETURN DATEDIFF ( a, b, SECOND ), 0 ) ) VAR Hours = INT ( Duration / 3600 ) VAR Minutes = INT ( MOD ( Duration, 3600 ) / 60 ) VAR Seconds = MOD ( MOD ( Duration, 3600 ), 60 ) VAR H = IF ( LEN ( Hours ) = 1, CONCATENATE ( "0", Hours ), CONCATENATE ( "", Hours ) ) VAR M = IF ( LEN ( Minutes ) = 1, CONCATENATE ( "0", Minutes ), CONCATENATE ( "", Minutes ) ) VAR S = IF ( LEN ( Seconds ) = 1, CONCATENATE ( "0", Seconds ), CONCATENATE ( "", Seconds ) ) RETURN CONCATENATE ( H, CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) )If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
2 Replies
- Greg_DecklerCommunity Champion
Ofire See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
__Current - __Previous - v-deddai1-msftCommunity Support
Hi Ofire ,
Assumed that your data is the same structure as the sample below:
Then you can use the following two measure:
Onduration = VAR Duration = SUMX ( 'Table', IF ( 'Table'[event] = "start", VAR a = 'Table'[Timestap] VAR b = CALCULATE ( MIN ( 'Table'[Timestap] ), FILTER ( 'Table', 'Table'[Timestap] >= a && 'Table'[event] = "stop" ) ) RETURN DATEDIFF ( a, b, SECOND ), 0 ) ) VAR Hours = INT ( Duration / 3600 ) VAR Minutes = INT ( MOD ( Duration, 3600 ) / 60 ) VAR Seconds = MOD ( MOD ( Duration, 3600 ), 60 ) VAR H = IF ( LEN ( Hours ) = 1, CONCATENATE ( "0", Hours ), CONCATENATE ( "", Hours ) ) VAR M = IF ( LEN ( Minutes ) = 1, CONCATENATE ( "0", Minutes ), CONCATENATE ( "", Minutes ) ) VAR S = IF ( LEN ( Seconds ) = 1, CONCATENATE ( "0", Seconds ), CONCATENATE ( "", Seconds ) ) RETURN CONCATENATE ( H, CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) ) Offduration = VAR Duration = SUMX ( 'Table', IF ( 'Table'[event] = "stop", VAR a = 'Table'[Timestap] VAR b = CALCULATE ( MIN ( 'Table'[Timestap] ), FILTER ( 'Table', 'Table'[Timestap] >= a && 'Table'[event] = "start" ) ) RETURN DATEDIFF ( a, b, SECOND ), 0 ) ) VAR Hours = INT ( Duration / 3600 ) VAR Minutes = INT ( MOD ( Duration, 3600 ) / 60 ) VAR Seconds = MOD ( MOD ( Duration, 3600 ), 60 ) VAR H = IF ( LEN ( Hours ) = 1, CONCATENATE ( "0", Hours ), CONCATENATE ( "", Hours ) ) VAR M = IF ( LEN ( Minutes ) = 1, CONCATENATE ( "0", Minutes ), CONCATENATE ( "", Minutes ) ) VAR S = IF ( LEN ( Seconds ) = 1, CONCATENATE ( "0", Seconds ), CONCATENATE ( "", Seconds ) ) RETURN CONCATENATE ( H, CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) )If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai