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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
KellerB
Frequent Visitor

Calculating Working hours excluding downtime and total units and Units per hour.

Hi! I have a problem that I have been trying to solve for days. I need to calculate working hours by manufacturing line over multiple days. Additionally I need to do it for specific shifts and count only the units that passed (1). I have to do this by time of first unit produced-time of last unit produced for each day. I dont know how to go through each day, take the min time and max time, subtract the two, and add to a running total going through everyday that my date slicer has included. If you are able to help that would be awesome!! Let me know

Here is some sample data. This will eventually allow me to calculate an accurate "Units per hour".
so for line 1 it should return (8am-4pm) + (7am-1pm) +(6am-2pm) = 22 hours worked and 6 total units, and 6units/22hours = 0.27 Units per hour. 
I have a summarized table that only considers Line number and just adds whatever number is in column "Passed", but now I need it to consider Line number for each shift and only add Passed units ("1" = YES) to Total units. Let me know if you can help 🙂 

Line NumberDateTimeUnitsPassed?Shift
19/20/20228am11Day
19/20/202210am10Day
19/20/20221pm10Day
19/20/20224pm11Day
19/21/20227am11Day
19/21/20229am11Day
19/21/202211am11Day
19/21/20221pm11Day
19/22/20226am11Day
19/22/202210am11Day
19/22/20222pm11Day
29/20/20228am11Day
29/20/202210am11Day
29/20/20221pm12Day
29/20/20224pm11Day
29/21/20227am11Day
29/21/20229am11Day
29/21/202211am11Day
29/21/20221pm11Day
29/22/20226am11Day
39/21/202210am11Day
39/21/20222pm11Day
39/22/20229am11Day
39/22/202211am13Day
39/22/20221pm11Day
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi. @KellerB ;

Try this measure.

 

Measure = 
SUMX(SUMMARIZE(FILTER(ALL('Table'),[Line Number]=MAX('Table'[Line Number])),[Line Number],[Date],"1",
DATEDIFF( 
    CALCULATE(MIN('Table'[Time]),ALLEXCEPT('Table','Table'[Line Number],'Table'[Date])), 
    CALCULATE(MAX('Table'[Time]),ALLEXCEPT('Table','Table'[Line Number],'Table'[Date])),
    HOUR)),[1])

 

The final show:

vyalanwumsft_0-1664861154601.png

Or try table by dax.

 

Newtable = SUMMARIZE(FILTER('Table',[Passed?]=1),[Line Number],[Date],
                     "max time",CALCULATE(MAX('Table'[Time]),ALLEXCEPT('Table','Table'[Date],'Table'[Line Number])),
                     "min time",CALCULATE(MIN('Table'[Time]),ALLEXCEPT('Table','Table'[Date],'Table'[Line Number])))

 

The final show:

vyalanwumsft_1-1664861469492.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


Best Regards,
Community Support Team _ Yalan Wu
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

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi. @KellerB ;

Try this measure.

 

Measure = 
SUMX(SUMMARIZE(FILTER(ALL('Table'),[Line Number]=MAX('Table'[Line Number])),[Line Number],[Date],"1",
DATEDIFF( 
    CALCULATE(MIN('Table'[Time]),ALLEXCEPT('Table','Table'[Line Number],'Table'[Date])), 
    CALCULATE(MAX('Table'[Time]),ALLEXCEPT('Table','Table'[Line Number],'Table'[Date])),
    HOUR)),[1])

 

The final show:

vyalanwumsft_0-1664861154601.png

Or try table by dax.

 

Newtable = SUMMARIZE(FILTER('Table',[Passed?]=1),[Line Number],[Date],
                     "max time",CALCULATE(MAX('Table'[Time]),ALLEXCEPT('Table','Table'[Date],'Table'[Line Number])),
                     "min time",CALCULATE(MIN('Table'[Time]),ALLEXCEPT('Table','Table'[Date],'Table'[Line Number])))

 

The final show:

vyalanwumsft_1-1664861469492.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

KellerB
Frequent Visitor

KellerB_0-1664806634255.png

This is what I currently have... I need some kind of if statement to only count Passed units = "1" and do a separate table for day shift and night shift...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.