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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculate ratio of sum of each status duration Vs. planned operational time duration

Hello,

 

Currently I am having trouble with calculating the ratio between the time duration of statusses of a machine and the planned operational time duration.

 

The table PlannedOperationalActivity contains the planned start and end time of the machine.

 

PlannedOperationalActivityIDDeviceIDMondayStartDateTimeMondayEndDateTimeTuesdayStartDateTimeTuesdayEndDateTimeWednesdayStartDateTimeWednesdayEndDateTimeThursdayStartDateTimeThursdayEndDateTimeFridayStartDateTimeFridayEndDateTime
1109:00:0018:00:0009:00:0018:00:0009:00:0018:00:0009:00:0018:00:0009:00:0018:00:00
2209:00:0018:00:0009:00:0018:00:0008:30:0017:30:0009:00:0018:00:0009:00:0018:00:00
3309:00:0018:00:0009:00:0013:00:0009:00:0018:00:0009:00:0013:00:0009:00:0013:00:00

 

The table DeviceOperationalState contains which status has occured and how long the status was active.

DeviceOperationalStateIDDeviceIDOperationalStateIDStateDateTimeStartStateDateTimeEnd
11702/01/2021 08:0002/01/2021 09:00
21402/01/2021 09:0002/01/2021 11:14
31302/01/2021 11:1402/01/2021 14:05
41502/01/2021 14:0502/01/2021 14:10
51402/01/2021 14:1002/01/2021 18:00
61802/01/2021 18:0002/01/2021 18:31
73721/01/2021 08:0021/01/2021 09:00
83421/01/2021 09:0021/01/2021 18:00
93821/01/2021 18:0021/01/2021 19:00

 

What I want to calculate is the sum of time for each status of a DeviceID for one day and devide this by the duration between the corresponding weekday planned time duration.

 

An example is 21/01/2021 of DeviceID 3, which is a thursday. The sum of the status durations is 60+540+60=660mins

The planned operational activity is ThursdayEndDateTime-ThursdayStartDateTime = 18:00:00-09:00:00 = 09:00:00 = 540mins.

The ratio is than 660/540*100 = 122%. StatusID 7 = 11%, StatusID 4=100% and StatusID 8 = 11%. 

In a chart I want to show per day of the month that the machine was active what the ratio was of planned operational time Vs. the actual time in which the total real active time bar is split in segments per status. 

 

Help is greatly appreciated.

 

 

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

Hi  @Anonymous  ,

Here are the steps you can follow:

1. Click Transform data to enter Power query, select [DeviceID], click Transform – Unpivot Columns – Unpivot Other Columns

v-yangliu-msft_0-1617868952074.png

Result:

v-yangliu-msft_1-1617868952083.png

2. Create calculated column.

datediff = DATEDIFF([StateDateTimeStart],[StateDateTimeEnd],MINUTE)

Result:

v-yangliu-msft_2-1617868952086.png

3. Create calculated table.

Summarize =
SUMMARIZE('Table (2)',[DeviceID],"Time duration",SUM('Table (2)'[datediff]),"Weekday",FORMAT(WEEKDAY(MAX('Table (2)'[StateDateTimeStart]),1),"dddd"))

Result:

v-yangliu-msft_3-1617868952087.png

4. Create calculated column.

Percent1 =
var _total=
SUMX(FILTER(ALL('Table (2)'),[DeviceID]=EARLIER('Table (2)'[DeviceID])),[datediff])
var _percent=
DIVIDE([datediff],_total)
var _related=
CALCULATE(MAX('Summarize'[Percent]),FILTER(ALL('Summarize'),[DeviceID]=EARLIER('Table (2)'[DeviceID])))
return
_related*_percent

5. Result:

v-yangliu-msft_4-1617868952090.png

 

Best Regards,

Liu Yang

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-yangliu-msft
Community Support
Community Support

Hi  @Anonymous  ,

Here are the steps you can follow:

1. Click Transform data to enter Power query, select [DeviceID], click Transform – Unpivot Columns – Unpivot Other Columns

v-yangliu-msft_0-1617868952074.png

Result:

v-yangliu-msft_1-1617868952083.png

2. Create calculated column.

datediff = DATEDIFF([StateDateTimeStart],[StateDateTimeEnd],MINUTE)

Result:

v-yangliu-msft_2-1617868952086.png

3. Create calculated table.

Summarize =
SUMMARIZE('Table (2)',[DeviceID],"Time duration",SUM('Table (2)'[datediff]),"Weekday",FORMAT(WEEKDAY(MAX('Table (2)'[StateDateTimeStart]),1),"dddd"))

Result:

v-yangliu-msft_3-1617868952087.png

4. Create calculated column.

Percent1 =
var _total=
SUMX(FILTER(ALL('Table (2)'),[DeviceID]=EARLIER('Table (2)'[DeviceID])),[datediff])
var _percent=
DIVIDE([datediff],_total)
var _related=
CALCULATE(MAX('Summarize'[Percent]),FILTER(ALL('Summarize'),[DeviceID]=EARLIER('Table (2)'[DeviceID])))
return
_related*_percent

5. Result:

v-yangliu-msft_4-1617868952090.png

 

Best Regards,

Liu Yang

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

HarishKM
Impactful Individual
Impactful Individual

@Anonymous  create a cal. col.
time diff = DATEDIFF(Sheet1[Start time],Sheet1[End time],MINUTE)
Then create 1 more measure for your operational time as well .
then divide update the format.
Anonymous
Not applicable

Hello @HarishKM

 

Thank you for responding.

 

Whilst following your instructions I have become stuck once again.

Your solution is creating a measure for operational time, assuming you mean with the same formula (

TimeDiffOperationalState = DATEDIFF(DeviceOperationalState[StateDateTimeStart],DeviceOperationalState[StateDateTimeEnd],MINUTE)). This formula is not possible because the measure does not accept anything but a measure. I created another calculated column instead with the same formula.
 
When creating a measure to divide both time durations, both calculated columns are not selectable. 
RatioTimeDurations = DIVIDE(PlannedOperationalActivity[ThursdayTimeDiffMin],DeviceOperationalState[TimeDiffOperationalStateColumn])
 
Also, this formula would only take in consideration the time difference if the weekday is Thursday. If the date is 22nd of Januari 2021, the formula should use friday Start and End as ratio and if it is the 20th of Januari 2021 the formula should use the time difference of Wednesday as ratio.
 
I try to attach the PBI file, but I'm not allowed to.
 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.