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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Show Duration Based on Time Spent

I am using an Excel table that has a Time Spent column formatted as Custom h:mm:ss.    When I pull this into PowerBI, and I try to show the total duration using the Card visual, I get the following result.   It doesn't add up the total duration.   I saw a post to create a Custom Column and subtract a particular date (1899,12,31) to get the duration -- that didn't work either. PowerBI Example.PNGExcel Example.PNG

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

Hi  @Anonymous  ,

You can use measure.

The calculated column will not change according to the selection of the slicer.

1. Create measure.

SumTime_meausre =
VAR TotalSeconds =
    SUMX(
        'IT Productivity Measurements',
        HOUR( 'IT Productivity Measurements'[Time Spent] ) * 3600
            + MINUTE( 'IT Productivity Measurements'[Time Spent] ) * 60
            + SECOND( 'IT Productivity Measurements'[Time Spent] )
    )
VAR Days = TRUNC( TotalSeconds/3600/24)
VAR Hors = TRUNC( (TotalSeconds-Days*3600*24 )/3600 )
VAR Mins = TRUNC( MOD( TotalSeconds,3600 )/60 )
VAR Secs = MOD( TotalSeconds, 60 )
RETURN
IF(DAYS=0,"",IF(DAYS>1,DAYS&"days ",Days&"day"))&IF(Hors<10,"0"&Hors,Hors)&":"&IF(Mins<10,"0"&Mins,Mins)&":"&IF(Secs<10,"0"&Secs,Secs)

2. Result:

v-yangliu-msft_0-1622713095959.png

 

Best Regards,

Liu Yang

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

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous  ,

You can use measure.

The calculated column will not change according to the selection of the slicer.

1. Create measure.

SumTime_meausre =
VAR TotalSeconds =
    SUMX(
        'IT Productivity Measurements',
        HOUR( 'IT Productivity Measurements'[Time Spent] ) * 3600
            + MINUTE( 'IT Productivity Measurements'[Time Spent] ) * 60
            + SECOND( 'IT Productivity Measurements'[Time Spent] )
    )
VAR Days = TRUNC( TotalSeconds/3600/24)
VAR Hors = TRUNC( (TotalSeconds-Days*3600*24 )/3600 )
VAR Mins = TRUNC( MOD( TotalSeconds,3600 )/60 )
VAR Secs = MOD( TotalSeconds, 60 )
RETURN
IF(DAYS=0,"",IF(DAYS>1,DAYS&"days ",Days&"day"))&IF(Hors<10,"0"&Hors,Hors)&":"&IF(Mins<10,"0"&Mins,Mins)&":"&IF(Secs<10,"0"&Secs,Secs)

2. Result:

v-yangliu-msft_0-1622713095959.png

 

Best Regards,

Liu Yang

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

v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous  ,

 

Which Total you are referring to has not changed, whether you add the all() function to your measure to exclude other groups, and judge whether the relationship between the table and the table is correct.

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. If it is really inconvenient, measure sharing is also possible.

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

https://app.box.com/s/13r54y783ayrre0kpqa5qcjk7p4h04uw 

https://app.box.com/s/q1pox9f53qa7cb5sx59lqb3260i716sj 

 

Above is the Excel table and PowerBI chart.    The Total Duration box on the PBI chart does not change the Total Duration when I select one or multiple Technicians.   It always shows 2 days 03:32:00.   The previous example earlier in the post is the original.   I trimmed the content down for the purpose of sharing this data.

v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create meausre.

datediff = DATEDIFF(0,MAX('Table'[Time Spent]),SECOND)
sum =
SUMX(ALL('Table'),[datediff])

2. Result:

v-yangliu-msft_0-1622188572417.png

 

Best Regards,

Liu Yang

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

selimovd
Super User
Super User

Hey @Anonymous ,

 

make sure the column you mention is in the format time:

selimovd_0-1621977717144.png

 

Then you can use the solution from that post to calculate the duration:

SumTime =
VAR TotalSeconds =
    SUMX(
        'Table Name',
        HOUR( 'Table Name'[Column] ) * 3600
            + MINUTE( 'Table Name'[Column] ) * 60
            + SECOND( 'Table Name'[Column] )
    )
VAR Days = TRUNC( TotalSeconds/3600/24)
VAR Hors = TRUNC( (TotalSeconds-Days*3600*24 )/3600 )
VAR Mins = TRUNC( MOD( TotalSeconds,3600 )/60 )
VAR Secs = MOD( TotalSeconds, 60 )
RETURN
IF(DAYS=0,"",IF(DAYS>1,DAYS&"days ",Days&"day"))&IF(Hors<10,"0"&Hors,Hors)&":"&IF(Mins<10,"0"&Mins,Mins)&":"&IF(Secs<10,"0"&Secs,Secs)

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Anonymous
Not applicable

Thank you both for the feedback.   I now have the following, which the totals don't change when selecting different technicians.

PBI.PNG

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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