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
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
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.