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

String Days and Hours, monthly

Hi,

 

I have a column which reports time worked in hours (per id/row).  This I can report on monthly and I can calculate monthly average.  However I am converting the hours using DAX to display Days & Hours 

 

String NewColumn =
var vHours=ROUND([Columnwithhours],0)
var vDays=int( vHours/24)
var vRemainingHours=MOD(vHours, 24)
return
vDays&" Days & "& vRemainingHours& " Hours"
 
So the final output is something that looks like......5 days 4 hours.  
 
However, I need to report with this 'NewColumn' containing days & hours at a monthly level, Average time worked per month.  When I include the new column in my table it reports per ID per month, something like this
 
 Hours workedDays & Hours
Jan120 days 12 hours
Jan220 days 22 hours
Jan100 days 10 hours
 
 
The final output I require would be 
 
 Ave hours workedDays & Hours
Jan482 days 0 hours
Feb552 days 7 hours
Mar502 days 2 hours

 

Any help would be much appreciated 

3 REPLIES 3
v-shex-msft
Community Support
Community Support

HI @KimNixon ,

You can try to use the following measure formula to calculate the average of work hour based on month and convert them to time duration string:

Measure =
VAR _avg =
    CALCULATE ( AVERAGE ( 'Table'[Hour] ), VALUES ( 'Table'[Date].[MonthNo] ) )
VAR _rand =
    ROUNDDOWN ( _avg, 0 )
RETURN
    IF (
        _avg >= 24,
        INT ( _rand / 24 ) & " day"
            & MOD ( _rand, 24 ) & " hours",
        _rand & " hours"
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

create an hourly measure. Create an avg of the sum.

Refer - this is the sum of Avg

https://community.powerbi.com/t5/Desktop/SUM-of-AVERAGE/td-p/197013

 

Then format this column to show final result in day format

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thank you for the steer, I am getting a circular reference error, I must be going wrong somewhere

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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.