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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
timbckr812
Regular Visitor

Wrong Time Calculation

 

Good Morning,

 

I have an issue with time calculation in Power BI. In my case, I’ve determined the production lead time for multiple orders and stored it in a table column in the time format "hh:mm:ss." Each of the orders has a different quantity, so my next step is to calculate the production time per unit.

My approach for this is:

Time per Unit =  
SUM('Production Orders'[Production Time])/SUM('Production Orders'[Quantity])

However, the result is incorrect. I’ve also tried saving the lead time in decimal format, but the result remains the same. The solution should be 00:00:55, but the result I am getting is 19:52:07.

Perhaps someone has an idea of where my mistake might be.

A sample file is attached.

 

OrderQuantityProduction Time
1200:03:10
2300:02:05
3400:04:52
4200:01:44
5400:02:36
6200:02:16

Thank you!

3 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @timbckr812  - First, convert the production time to a numerical value, i.e., seconds, to ensure proper summing.

 

create a measure as follows;
Production Time per Unit =
VAR TotalTimeSeconds = SUMX('Production Orders',
(HOUR('Production Orders'[Production Time]) * 3600) +
(MINUTE('Production Orders'[Production Time]) * 60) +
SECOND('Production Orders'[Production Time]))
VAR TotalQuantity = SUM('Production Orders'[Quantity])
VAR TimePerUnitSeconds = TotalTimeSeconds / TotalQuantity
RETURN
FORMAT(TIME(0,0,TimePerUnitSeconds), "hh:mm:ss")

rajendraongole1_0-1737801320738.png

 

It sum the total production time in seconds and divide by the total quantity. please check the above and let know.





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

Proud to be a Super User!





View solution in original post

divyed
Super User
Super User

Hello @timbckr812 ,

 

You can try below dax :

Time per Unit =
VAR TotalMinutes = SUMX(
'Production Orders',
HOUR('Production Orders'[Production Time]) * 60 +
MINUTE('Production Orders'[Production Time]) +
SECOND('Production Orders'[Production Time]) / 60
)
VAR TotalQuantity = SUM('Production Orders'[Quantity])
VAR MinutesPerUnit = TotalMinutes / TotalQuantity
RETURN
TIME(INT(MinutesPerUnit / 60), INT(MOD(MinutesPerUnit, 60)), 0)

 

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

View solution in original post

danextian
Super User
Super User

Hi @timbckr812 

 

I can't replicate your expected result using your sample data even if the time per unit is evaluated separately for each order and then summed up in the total row but I am definitely not getting  19:52:07

danextian_0-1737804407368.png

Attached is the sample pbix used in the screenshot.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

8 REPLIES 8
danextian
Super User
Super User

Hi @timbckr812 

 

I can't replicate your expected result using your sample data even if the time per unit is evaluated separately for each order and then summed up in the total row but I am definitely not getting  19:52:07

danextian_0-1737804407368.png

Attached is the sample pbix used in the screenshot.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

First of all thanks for your reply 🙂

This is my solution. As soon as I format the time as a decimal number, I get results that differ from yours. There's always a "1" before the decimal point—could that be the problem? How do i fix that?

 

Production Time Picture.png

Is an order equivalent to a single record in your data or there are multiple records involved?  If there are multiple records which is not in your descrption, that's the only reason I can think of why your sum is overstated.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Yes ist equvalent to a single record.  I import the files from an Excel file, where the production time is stored in time format. As soon as I load the data into Power BI and then convert it into a decimal number, I get the "1" before the decimal point. Please see the attached images.Data import to Power BI.pngTime Format to Deicmal.png

I got it now, the import type was datetime and not time, as seen in the picture. My bad thank you!!

divyed
Super User
Super User

Hello @timbckr812 ,

 

You can try below dax :

Time per Unit =
VAR TotalMinutes = SUMX(
'Production Orders',
HOUR('Production Orders'[Production Time]) * 60 +
MINUTE('Production Orders'[Production Time]) +
SECOND('Production Orders'[Production Time]) / 60
)
VAR TotalQuantity = SUM('Production Orders'[Quantity])
VAR MinutesPerUnit = TotalMinutes / TotalQuantity
RETURN
TIME(INT(MinutesPerUnit / 60), INT(MOD(MinutesPerUnit, 60)), 0)

 

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

Works perfect, thank!!

rajendraongole1
Super User
Super User

Hi @timbckr812  - First, convert the production time to a numerical value, i.e., seconds, to ensure proper summing.

 

create a measure as follows;
Production Time per Unit =
VAR TotalTimeSeconds = SUMX('Production Orders',
(HOUR('Production Orders'[Production Time]) * 3600) +
(MINUTE('Production Orders'[Production Time]) * 60) +
SECOND('Production Orders'[Production Time]))
VAR TotalQuantity = SUM('Production Orders'[Quantity])
VAR TimePerUnitSeconds = TotalTimeSeconds / TotalQuantity
RETURN
FORMAT(TIME(0,0,TimePerUnitSeconds), "hh:mm:ss")

rajendraongole1_0-1737801320738.png

 

It sum the total production time in seconds and divide by the total quantity. please check the above and let know.





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

Proud to be a Super User!





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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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