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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
shannon8000
Frequent Visitor

PBI seconds conversion to hh:mm

Hello,

I've tried two different formulas I've found in these forums.  At first it looks like it is working but then the math isn't mathing when reviewing the output.

In the below example, you can see 7200 seconds is calclating to 1 hour however is should be 2 hours.  You can then see there are several 3600 second items that correctly display as 1 hour.  I exported to excel and did an Excel conversion and found several instances where the PBI calculation appears correctly and in others not with no identifiable pattern.   Of 14 instances of 14400 seconds, 3 PBI shows as 2 hours and the remaining correct at 4 hours.  

shannon8000_0-1703885994066.png

 

I've tried both formulas below:

Duration_ACTVTY =
VAR Duration = [ACTVTY_TTL_SEC]
// There are 3,600 seconds in an hour
VAR Hours =
INT ( [ACTVTY_TTL_SEC]/ 3600)
// There are 60 seconds in a minute
VAR Minutes =
INT ( MOD( [ACTVTY_TTL_SEC] - ( Hours * 3600 ),3600 ) / 60)
// Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours
VAR Seconds =
ROUNDUP(MOD ( MOD( [ACTVTY_TTL_SEC] - ( Hours * 3600 ),3600 ), 60 ),0) // We round up here to get a whole number
// These intermediate variables ensure that we have leading zero's concatenated onto single digits
// Hours with leading zeros
VAR H =
IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours )
)
// Minutes with leading zeros
VAR M =
IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes )
)
// Seconds with leading zeros
VAR S =
IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds )
)
// Now return hours, minutes and seconds with leading zeros in the proper format "hh:mm:ss"
RETURN
CONCATENATE (
H,
CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) )
)
 
and
hhmm test activity =
VAR hours =
    ROUNDDOWN ( [ACTVTY_TTL_SEC] / 3600, 0 )
VAR minutes =
    ROUNDDOWN ( MOD ( [ACTVTY_TTL_SEC], 3600 ) / 60, 0 )
VAR seconds =
    INT ( MOD ( [ACTVTY_TTL_SEC], 60 ) )

RETURN
    FORMAT(hours,"00") & ":"
        & FORMAT(minutes, "00")
        & ":"
        & FORMAT(seconds, "00")
 
Any ideas?  I checked the source data and there aren't any instances where the seconds are configured any differently than the others.  TIA 🙂
3 REPLIES 3
aj1973
Community Champion
Community Champion

Hi @shannon8000 

Here is an example

aj1973_0-1703887901490.png

and here is the formula

Total duration =
var _seconds = SUM(Sheet1[ACTVTY_TTL_SEC])
var _minutes = INT(_seconds / 60)
var _RemainingSeconds = MOD(_seconds, 60)
var _Hours = INT(_minutes / 60)
var _RemainingMinutes = MOD(_minutes, 60)
var _Days = INT(_Hours / 24)
var _RemainingHours = MOD(_Hours, 24)
return
_Days & " D : " &
_RemainingHours & " H : " &
_RemainingMinutes & " M : " &
_RemainingSeconds & " S  "
 
 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Hi Amine!

 

I applied as recommended and the output was interesing.

 

shannon8000_0-1703889612112.png

I will poke around some more to see what is happening.

You have a relationship problem in your Matrix or Table visual.

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.