cancel
Showing results for
Did you mean:
Helper I

## Viewing Minutes (Decimal) to Duration with total

Hello!

I have a report from our LMS showing viewing minutes as a decimal. I would like to create a new column that converts the decimal minutes to a duration where I see the total duration per course as well.

I have tried various suggested measures as well and got a duration to show, but then I wasn't able to get a total.

Any suggestions will be so appreciated.

In Excel it looks like this:

This is where I can get to inside my Power BI file:

The Viewing duration is based on a measure:

Viewing Duration2 = FORMAT([Viewing Seconds]/86400,"Long Time")

I have been struggling with this one.

Thank you,
Lisa

1 ACCEPTED SOLUTION
Super User

@Lisa-Eagle Maybe:

VAR seconds = ROUND( MOD ( MOD ( total, 3600 ), 60 ), 2 )

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
10 REPLIES 10
Helper I

@Greg_DecklerI am having an issue with longer durations.

I tried to adapt the measure as follows but it didn't work. I would like the hours to not show more than 24hrs and for the days number to adapt accordingly.

Total Duration Measure =
VAR total =
VAR weeks =
INT (total /604800 )
VAR days =
INT ( total / 86400 )
VAR hours =
INT ( total / 3600 )
VAR minutes =
INT ( MOD ( total, 3600 ) / 60 )
VAR seconds =
ROUNDUP( MOD ( MOD ( total, 3600 ), 60 ), 0 )
RETURN
weeks & " wks "
& days
& " days "
&  hours
&" hrs "
& minutes
& " min "
& seconds
& " sec"

Any ideas what I can try?

Thanks

Lisa Taylor

Helper I

@Greg_Deckler I am still experiencing some issues with my duration and hoping you can point me in the right direction.

Issue 1 is that I would like to adapt the measure to only show a total of 24 hours as there are 24 hours in a day.

When I try to show a total duration I get the following:

Issue 2 is if I select to filter my table by group my duration measure is not maintained and I only get blanks dhms.

Current duration measure is:

CE Course Completion Duration =
VAR total =
SUM ('Course Enrollments'[# of Seconds to Completion] )
VAR days =
INT ( total / 86400 )
VAR hours =
INT ( total / 3600 )
VAR minutes =
INT ( MOD ( total, 3600 ) / 60 )
VAR seconds =
ROUNDUP( MOD ( MOD ( total, 3600 ), 60 ), 0 )
RETURN
days & " d "
&  hours
&" h "
& minutes
& " m "
& seconds
& " s"

Super User

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Helper I

@Greg_Deckler Not sure where I am going wrong with this?

Super User

@Lisa-Eagle Since that is a Column instead of a Measure, ditch the SUM in your Duration variable and just reference the column directly.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Helper I

@Greg_Deckler thank you for your help thus far. I've managed to get the correct duration to display using your code from 2016.

See below screenshot. My question is now how can I show a sum of this column similar to the total shown under viewing minutes in my table.

You are a life saver, thanks again.

Super User

@Lisa-Eagle First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Helper I

@Greg_Deckler thank you for sharing those links. I so wish this totals issue was easier.

I have managed to get a total duration to show using the measure in below image. This is the closest I have gotten to what I would like to visualise. Only challenge now is how to adapt this measure so that seconds is rounded up to 2 places. Any ideas on that one please?

Super User

@Lisa-Eagle Maybe:

VAR seconds = ROUND( MOD ( MOD ( total, 3600 ), 60 ), 2 )

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Helper I

Thank you @Greg_Deckler that worked. I managed to adapt my measure to include days as well and used roundup for the seconds. Pretty cool. I am very grateful to you and this forum.

Announcements

#### Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

#### Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

#### Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

#### Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors