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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Dane
Helper I
Helper I

How to calculate machine hours in DAX

I have the following data in an SQL table. There are numerous Station ID's and each station ID has numerous scans per day. I would like to be able to get the first and last scan of each day and calculate the hours between those 2 times to obtain the length of time the machine was running. I am using Direct Query and was getting an error message using the min function when trying to calculate square feet per hour. 

 

 

Dane_0-1642709803083.png

 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

HI @Dane 

 

You can split the DateTime column to two columns for Time and Date, then use these codes to find the first and last time for each date:

 

First = calculate(MIN(table[Time]),allexcept(table,table[Date]))
Last = calculate(MAX(table[Time]),allexcept(table,table[Date]))

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

HI @Dane 

 

You can split the DateTime column to two columns for Time and Date, then use these codes to find the first and last time for each date:

 

First = calculate(MIN(table[Time]),allexcept(table,table[Date]))
Last = calculate(MAX(table[Time]),allexcept(table,table[Date]))

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

ALLUREAN
Solution Sage
Solution Sage

Hi, @Dane 

Please check this example:

https://www.dropbox.com/s/tf68z9rra5aameo/How%20to%20calculate%20machine%20hours%20in%20DAX%28allure...

 

Did I answer your question? Please Like and Mark my post as a solution if it solves your issue. Thanks.

Appreciate your Kudos !!!

https://allure-analytics.com/

https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA

https://www.linkedin.com/company/77757292/




Did I answer your question? Mark my post as a solution!


https://allure-analytics.com/
https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA
https://www.linkedin.com/company/77757292/

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors