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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Deelip
Resolver I
Resolver I

Calculating total amount of time machine stopped or running

Hi All,

 

I need some help in getting my head around this problem. I am trying to calculate the total time spent by a machine in running or stopped as per the date range selected, also trying to calculate this hours only for business hours which is 6AM to 8PM (monday to friday).

 

have attached four days of sample data to calculate total amount of time machine was stopped and total amount of time machine was running ( considering only 6AM -8PM everyday and only weekdays).

 

This is a Directquery table. I tried to go over some of the related posts in this forum but none of them are working as expected or I am not implementing it correctly.  

 

My timestamp column in power query looks like below and this could the reason maybe I cannot filter this table using my calendar table date column. All I get is blank rows in table visual when I try to filter this fact table with my date table. 

 

Deelip_0-1738007271132.png

 

sample data I dumped into excel: 

Deelip_1-1738008003773.png

 

Any help or thoughts on handling this problem is appreciated and definitely a good learning approach for me.

 

https://docs.google.com/spreadsheets/d/1yLvdgfUlXUDNOY5f_4f1zA4vOR9hbdlq/edit?usp=sharing&ouid=11513...

Thank you!!

2 REPLIES 2
muhammad_786_1
Super User
Super User

Hi @Deelip,

 

You can create these three calculated columns in your table using the following DAX expressions:

IsBusinessHour =
IF(
HOUR('Table'[Timestamp]) >= 6 && HOUR('Table'[Timestamp]) < 20,
TRUE,
FALSE
)

IsWeekday =
IF(
WEEKDAY('Table'[timestamp], 2) <= 5,
TRUE,
FALSE
)

PacketID =
SUMX(
FILTER(
'Table',
'Table'[timestamp] <= EARLIER('Table'[timestamp]) &&
'Table'[Belt] <> EARLIER('Table'[Belt])
),
1
) + 1

 

Finally, you can use this measure in your report to calculate the total running time in minutes of the machine.

TotalRunningTime =
SUMX(
SUMMARIZE(
FILTER(
'Table',
'Table'[Belt] = "Running" &&
'Table'[IsBusinessHour] = TRUE &&
'Table'[IsWeekday] = TRUE
),
'Table'[PacketID],
"PacketStartTime", MIN('Table'[timestamp]),
"PacketEndTime", MAX('Table'[timestamp])
),
DATEDIFF([PacketStartTime], [PacketEndTime], MINUTE) + 1
)

 

I've also attached a link to a reference file. You can check it out as well.

 

File

 

Best Regards,
Muhammad Yousaf

 

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

 

LinkedIn

Hi @muhammad_786_1 

 

Thank you so much for looking into this. 

 

I cannot create the third calculated column as I am getting the below error... just an fyi...Belt is also a calculated column.

Deelip_0-1738026648375.png

Thanks!

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.