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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
ggoode
Frequent Visitor

Using a calculated duration in visuals - is this now possible?

So I had a total seconds measure, that using dax I put into a duration of days:hours:minutes:seconds, but I can not use that in any visuals. I know years ago when I tried doing things like this there was no way to use measures in visuals but from what I can tell that has recently changed. 

 

Is there a way to convert total seconds into a days/hours/minutes/seconds format that you are able to use in visuals? 

 

Thanks

1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @ggoode 

Based on your needs, I have created the following form.

 

vjialongymsft_0-1705912126539.png

 

You can use the following dax to get the result you want

Measure = 
     VAR TotalSeconds = SELECTEDVALUE('Table'[seconds])
     VAR Seconds = MOD(TotalSeconds, 60)
     VAR Minutes = MOD(INT(TotalSeconds / 60), 60)
     VAR Hours = MOD(INT(TotalSeconds / 3600), 24)
     VAR Days = INT(TotalSeconds / 86400)
     RETURN
     FORMAT(Days, "00") & " days " & 
     FORMAT(Hours, "00") & ":" & 
     FORMAT(Minutes, "00") & ":" & 
     FORMAT(Seconds, "00")

 

vjialongymsft_1-1705912202788.png

 

Best Regards,

Jayleny

 

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
v-jialongy-msft
Community Support
Community Support

Hi @ggoode 

Based on your needs, I have created the following form.

 

vjialongymsft_0-1705912126539.png

 

You can use the following dax to get the result you want

Measure = 
     VAR TotalSeconds = SELECTEDVALUE('Table'[seconds])
     VAR Seconds = MOD(TotalSeconds, 60)
     VAR Minutes = MOD(INT(TotalSeconds / 60), 60)
     VAR Hours = MOD(INT(TotalSeconds / 3600), 24)
     VAR Days = INT(TotalSeconds / 86400)
     RETURN
     FORMAT(Days, "00") & " days " & 
     FORMAT(Hours, "00") & ":" & 
     FORMAT(Minutes, "00") & ":" & 
     FORMAT(Seconds, "00")

 

vjialongymsft_1-1705912202788.png

 

Best Regards,

Jayleny

 

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

 

 

ajohnso2
Responsive Resident
Responsive Resident

I would keep the calculation as integer total seconds and explore the use of applying dynamic formatting to the new measure.

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-dynamic-format-strings

Great idea! Exactly the kind of relatively new feature I was looking for. I got it to work with this method, but I noticed that in the axis, the scale labels are not appearing as the should. They all just appear as the max number in the visual. Are you familar with this bug, and any possible workarounds? 

 

Thanks!

ajohnso2
Responsive Resident
Responsive Resident

I'm logged off for the day now, if you could post a sample pbix I can take a look tomorrow

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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