Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I wrote a format string using ChatGPT but it's not working 100% correctly in certain situations. Below is the code I'm using for dynamic formatting:
Does anyone have any ideas on how to fix this? I want to use dynamic formatting so that I can utilize the bars in the cell, so the actual measure needs to stay as an integer instead of text (like the "TimeFormattedMeasure" to the left.)
Solved! Go to Solution.
Hi, @peterg0417
Based on your information, I create a sample table:
Then create a calculated column, try the following DAX:
Column =
VAR TotalSeconds = [Latest Execution Time(ss)]
VAR Hours = INT(TotalSeconds / 3600)
VAR Minutes = INT(MOD(TotalSeconds, 3600) / 60)
VAR Seconds = INT(MOD(TotalSeconds, 60))
VAR HoursText = IF(Hours > 0, Hours & "h ", "")
VAR MinutesText = IF(Minutes > 0, Minutes & "m ", "")
VAR SecondsText = IF(Seconds > 0, Seconds & "s", "")
RETURN
IF(TotalSeconds = 0, "0", TRIM(HoursText & MinutesText & SecondsText))
Here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @peterg0417
Based on your information, I create a sample table:
Then create a calculated column, try the following DAX:
Column =
VAR TotalSeconds = [Latest Execution Time(ss)]
VAR Hours = INT(TotalSeconds / 3600)
VAR Minutes = INT(MOD(TotalSeconds, 3600) / 60)
VAR Seconds = INT(MOD(TotalSeconds, 60))
VAR HoursText = IF(Hours > 0, Hours & "h ", "")
VAR MinutesText = IF(Minutes > 0, Minutes & "m ", "")
VAR SecondsText = IF(Seconds > 0, Seconds & "s", "")
RETURN
IF(TotalSeconds = 0, "0", TRIM(HoursText & MinutesText & SecondsText))
Here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hI @peterg0417 Considering you want to convert total seconds to hour, minutes, and seconds. Try below Codes:
Hope this helps!!
If this solved your problem, please accept it as a soltuion!!
Best Regards,
Shahariar Hafiz
I tried putting your code in as dynamic formatting but the error is still there. It looks like it's entering 2 digits (74 and 13, for the 2 lines) in between the correct value for seconds.
If your time formatted measure is correctly evaluting then use that measure. Since don't know much about your data, it is hard to tell what exactly happening. If you have total seconds, then the provided measure should evalutes correctly.
Hi @peterg0417
Did you have a column that shows the total second? if not craete a column as follows:
VAR _hour = RIGHT("0" & ROUNDDOWN(_sum / 3600, 0), 2)
VAR _minute = RIGHT("0" & ROUNDDOWN(MOD(_sum, 3600) / 60, 0), 2)
VAR _second = RIGHT("0" & MOD(_sum, 60), 2)
RETURN
_hour & ":" & _minute & ":" & _second
If this post helps, then I would appreciate a thumbs up 👍 and mark it as the solution to help the other members find it more quickly.
Yes. I already have a column that shows duration in seconds.
I also have a measure, Latest Execution Time, returns the latest duration (that's the requirement, in case there's more than 1 run per model on a given day.)
I need to Latest Execution Time from seconds to minutes and seconds while still keeping it as an integer, therefore I need to do it using dynamic formatting.
then you can use your measure instead of _sum variable
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
74 | |
73 | |
56 | |
38 | |
31 |
User | Count |
---|---|
84 | |
63 | |
63 | |
49 | |
45 |