Forum Discussion
Help Needed: Converting Seconds/Milliseconds Field to HH:MM:SS Format in Power BI
Hi everyone,
I hope you're all doing well. I'm currently working on a project where I need to convert a field containing seconds/milliseconds into the HH:MM:SS format in Power BI. In Tableau, I successfully used the following formula:
```
Available (AVG) = AVG([Available])
```
Available (AVG) (HH:MM:SS) =
IIF([Available (AVG)] % 60 == 60, 0, [Available (AVG)] % 60) +
IIF(INT([Available (AVG)] / 60) % 60 == 60, 0, INT([Available (AVG)] / 60) % 60) * 100 +
IIF(INT([Available (AVG)] / 3600) % 24 == 0, 0, INT([Available (AVG)] / 3600) % 24) * 10000
```
However, when trying to replicate this in Power BI, I encountered some issues with the accuracy of the results. Here's the DAX expression I used:
```
AverageAvailableTime =
DIVIDE(
SUM('STATUS_SUBHOUR_V'[AVAILABLE]),
COUNTROWS('STATUS_SUBHOUR_V')
)
```
AverageAvailableTimeFormatted =
FORMAT(
TIME(
INT([AverageAvailableTime] / 3600), // Hours
INT(MOD([AverageAvailableTime] / 60, 60)), // Minutes
INT(MOD([AverageAvailableTime], 60)) // Seconds
),
"HH:mm:ss"
)
```
The results I'm getting in Power BI are not matching what I achieved in Tableau. Could someone please guide me on the correct approach to convert a seconds/milliseconds field to HH:MM:SS format in Power BI?
Any help or insights would be greatly appreciated.
Thank you!
Manoj Prabhakar
- Anonymous2 years ago
Hi manoj_0911 ,
You can refer the methods in the following links to get it:
Calculate Duration in Days Hours Minutes and Seconds Dynamically in Power BI using DAX - RADACAD
String Duration in Hours Minutes and Seconds = var vSeconds=[Duration in Seconds] var vMinutes=int( vSeconds/60) var vRemainingSeconds=MOD(vSeconds, 60) var vHours=INT(vMinutes/60) var vRemainingMinutes=MOD(vMinutes,60) return vHours&":"& vRemainingMinutes&":"& vRemainingSecondsSolved: Re: Incorrect sum of time (hh:mm:ss) - Microsoft Fabric Community
Best Regards
1 Reply
- AnonymousNot applicable
Hi manoj_0911 ,
You can refer the methods in the following links to get it:
Calculate Duration in Days Hours Minutes and Seconds Dynamically in Power BI using DAX - RADACAD
String Duration in Hours Minutes and Seconds = var vSeconds=[Duration in Seconds] var vMinutes=int( vSeconds/60) var vRemainingSeconds=MOD(vSeconds, 60) var vHours=INT(vMinutes/60) var vRemainingMinutes=MOD(vMinutes,60) return vHours&":"& vRemainingMinutes&":"& vRemainingSecondsSolved: Re: Incorrect sum of time (hh:mm:ss) - Microsoft Fabric Community
Best Regards