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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
manoj_0911
Helper IV
Helper IV

Need Help - Converting Seconds to HH:MM:SS and Calculating Average Duration

Need Help - Converting Seconds to HH:MM:SS and Calculating Average Duration

Hi everyone,

I'm seeking assistance with two calculations in Power BI:

1. Converting Seconds to HH:MM:SS Format:

I'm working with a column named `ACW_DURATION` that stores durations in seconds. I've tried the following formula:

```
ACWDurationFormatted = 
FORMAT(
  TIME(
    INT('AGENT_SUBHOUR_V'[ACW_DURATION] / 3600), // Hours
    INT(MOD('AGENT_SUBHOUR_V'[ACW_DURATION] / 60, 60)), // Minutes
    INT(MOD('AGENT_SUBHOUR_V'[ACW_DURATION], 60)) // Seconds
  ),
  "HH:mm:ss"
)
```

However, I'm encountering issues (getting incorrect values or duplicates). Can someone please confirm if this formula is correct and suggest any troubleshooting tips?

2. Calculating Average Duration (ACW Time per Call):

I have two columns: `ACW_DURATION` (seconds) and `ACW_COUNT` (number of calls). I've tried two approaches to calculate the average duration per call:

a. Using SUMX and IF:

```
AverageACWDuration = 
IF(
  ISBLANK(SUM('AGENT_SUBHOUR_V'[ACW_COUNT])),
  BLANK(),
  SUM('AGENT_SUBHOUR_V'[ACW_DURATION]) / SUM('AGENT_SUBHOUR_V'[ACW_COUNT])
)
```

**b. Using DIVIDE:**

```
AverageACWDuration new = 
DIVIDE(
  SUM('AGENT_SUBHOUR_V'[ACW_DURATION]),
  SUM('AGENT_SUBHOUR_V'[ACW_COUNT]),
  0
)
```

Both methods seem to return unexpected results. Could anyone advise on the best approach for calculating the average duration per call and suggest corrections to the formulas if needed?

 

manoj_0911_0-1712210403945.png

 

ALL ACW CALCULATIONS I HAVE , 

 

ACWDurationFormatted =
FORMAT(
TIME(
INT('AGENT_SUBHOUR_V'[ACW_DURATION] / 3600), // Hours
INT(MOD('AGENT_SUBHOUR_V'[ACW_DURATION] / 60, 60)), // Minutes
INT(MOD('AGENT_SUBHOUR_V'[ACW_DURATION], 60)) // Seconds
),
"HH:mm:ss"
)
-------------------------------------------------------------------------------
AverageACWDuration =
IF(
ISBLANK(SUM('AGENT_SUBHOUR_V'[ACW_COUNT])),
BLANK(),
SUM('AGENT_SUBHOUR_V'[ACW_DURATION]) / SUM('AGENT_SUBHOUR_V'[ACW_COUNT])
)
-------------------------------------------------------------------------------
AverageACWDuration new =
DIVIDE(
SUM('AGENT_SUBHOUR_V'[ACW_DURATION]),
SUM('AGENT_SUBHOUR_V'[ACW_COUNT]),
0
)
-------------------------------------------------------------------------------
AverageACWDurationFormatted new =
IF(
ISBLANK([AverageACWDuration new]),
BLANK(),
FORMAT(
TIME(
INT([AverageACWDuration new] / 3600), // Hours
INT(MOD([AverageACWDuration new] / 60, 60)), // Minutes
INT(MOD([AverageACWDuration new], 60)) // Seconds
),
"HH:mm:ss"
)
)
-------------------------------------------------------------------------------

 

Thanks in advance for your support!
Manoj Prabhakar

1 ACCEPTED SOLUTION
Joe_Barry
Solution Supplier
Solution Supplier

Hi @manoj_0911 

 

 

I can partly help

Create custom columns.

 

Hours = INT([Seconds] / 3600)
Minutes = INT(MOD([Seconds], 3600) / 60)
Seconds = MOD([Seconds], 60)
 
Then create another
DurationFormatted =
FORMAT([Hours], "00") & ":" &
FORMAT([Minutes], "00") & ":" &
FORMAT([Seconds], "00")
 
Joe_Barry_0-1712212435363.png

 

Hope this helps

Joe

 

If you found my answer helpful and it solved your issue, please accept as solution

 

 
 
 

 

 

View solution in original post

3 REPLIES 3
Joe_Barry
Solution Supplier
Solution Supplier

Hi @manoj_0911 

 

 

I can partly help

Create custom columns.

 

Hours = INT([Seconds] / 3600)
Minutes = INT(MOD([Seconds], 3600) / 60)
Seconds = MOD([Seconds], 60)
 
Then create another
DurationFormatted =
FORMAT([Hours], "00") & ":" &
FORMAT([Minutes], "00") & ":" &
FORMAT([Seconds], "00")
 
Joe_Barry_0-1712212435363.png

 

Hope this helps

Joe

 

If you found my answer helpful and it solved your issue, please accept as solution

 

 
 
 

 

 

Hi @Joe_Barry  I appreciate your response, it was really helpful, but I still have some questions. First, my dataset contains 40 durations of this type; given that this is ivr data, can i follow the same approach to convert it to HH:MM:SS? Additionally, for a given average ACW time, I must divide the ACW duration in seconds by the accepted count before converting the result to the hh:mm:ss format. I did this in Tableau; is there a comparable method in Power Bi?" "

AVERAGE ACW TIME = ZN(SUM([ACW DURATION])/SUM([ACCEPTED]))

AVG ACW TIME = IIF([AVERAGE ACW TIME] % 60 == 60,0,[AVERAGE ACW TIME] % 60)// seconds
+ IIF(INT([AVERAGE ACW TIME]/60) %60 == 60, 0, INT([AVERAGE ACW TIME]/60) %60) * 100 //minutes
+ INT([AVERAGE ACW TIME]/3600) * 10000 //hours

"

Without really knowing the data, I would suggest that you find the average before you convert to hh:mm:ss.

 

Try and test first to see if you get the result you require

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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