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
Viswajth_Nair95
Frequent Visitor

Finding the total hours ever day

Viswajth_Nair95_0-1652945678278.png

i have production data coming in like this, for each day. i have to calculate the number of production hours for each day in a seperate coulumn. since i am a beginner, i tried out some things but couldnt work it out.  Please help?

1 ACCEPTED SOLUTION

Hi @Viswajth_Nair95 ,

 

If Hour part and Mintue part in your code return blank, you will get result"::00". I suggest you to update your code as below. If there is no working hours in that day, your measure will return "00:00:00".

Measure = 
VAR _HOUR = 
SUMX ( 'Query1', HOUR ( 'Query1'[Time] ) )
    + TRUNC ( SUMX ( 'Query1', MINUTE ( 'Query1'[Time] ) ) / 60 ) 
VAR _MINUTE = MOD ( SUMX ( 'Query1', MINUTE ( 'Query1'[Time] ) ), 60 )
RETURN
IF(_HOUR = 0,"00",_HOUR)& ":"
& IF(_MINUTE = 0,"00",_MINUTE) & ":00"

 

Best Regards,
Rico Zhou

 

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

4 REPLIES 4
Viswajth_Nair95
Frequent Visitor

Thank you @Samarth_18 , but it didnt fully work on a large data set somehow. i ended up getting total hours in the last 3 days o the year and blank in the other

 

Viswajth_Nair95_0-1653376555285.png

Maybe it might be because i made some mistakes in the formula.

the name of the table is Query1, the date column is Date and Time column Time. I put in the following formula:

 

Measure=SUMX ( 'Query1', HOUR ( 'Query1'[Time] ) )
+ TRUNC ( SUMX ( 'Query1', MINUTE ( 'Query1'[Time] ) ) / 60 ) & ":"
& MOD ( SUMX ( 'Query1', MINUTE ( 'Query1'[Time] ) ), 60 ) & ":00"
 

Hi @Viswajth_Nair95 ,

 

If Hour part and Mintue part in your code return blank, you will get result"::00". I suggest you to update your code as below. If there is no working hours in that day, your measure will return "00:00:00".

Measure = 
VAR _HOUR = 
SUMX ( 'Query1', HOUR ( 'Query1'[Time] ) )
    + TRUNC ( SUMX ( 'Query1', MINUTE ( 'Query1'[Time] ) ) / 60 ) 
VAR _MINUTE = MOD ( SUMX ( 'Query1', MINUTE ( 'Query1'[Time] ) ), 60 )
RETURN
IF(_HOUR = 0,"00",_HOUR)& ":"
& IF(_MINUTE = 0,"00",_MINUTE) & ":00"

 

Best Regards,
Rico Zhou

 

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

 

 

@Viswajth_Nair95 Is it possible for you to share the PBIX file after removing sensitive data?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Samarth_18
Community Champion
Community Champion

Hi @Viswajth_Nair95 

 

You could create a measure as below:-

 

Measure =
SUMX ( 'table', HOUR ( 'Table'[hours] ) )
    + TRUNC ( SUMX ( 'table', MINUTE ( 'Table'[hours] ) ) / 60 ) & ":"
    & MOD ( SUMX ( 'table', MINUTE ( 'Table'[hours] ) ), 60 ) & ":00"

 

Dataset:-

Samarth_18_0-1652947474981.png

 

Output:-

Samarth_18_1-1652947498905.png

BR,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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.

Top Solution Authors