Forum Discussion

stubax's avatar
stubax
Frequent Visitor
3 years ago

Time on Y-Axis

Thought I would show a simple solution for adding time format to Y-Axis of charts as I couldn't find a solution for this - 

starting with a simple dataset below - (time is in time format HH:MM:SS)

 

 

Step 1 -

Add a new column turning time into a decimal in hours e.g. 01:30:00 = 1.5 hours 

using formula - 

Decimal Time = Data[Time]*24

 

Step 2 -
Add new measure summing this new column
using formula - 
SumofDecimalTime = sum(Data[Decimal Time])
 
Step 3 - 
Add new measure converting SumofDecimalTime measure into time format
using formula - 
HH:MM:SS =
VAR vHoursDecimal = [SumofDecimalTime]
VAR vHours = INT ( vHoursDecimal )
VAR vMinutesDecimal = 60 * ( vHoursDecimal - vHours )
VAR vMinutes = INT ( vMinutesDecimal )
VAR vSeconds = ROUND ( 60 * ( vMinutesDecimal - vMinutes ), 0 )
VAR vHH = IF ( LEN ( vHours ) = 1, "0" & vHours, vHours )
VAR vMM = IF ( LEN ( vMinutes ) = 1, "0" & vMinutes, vMinutes )
VAR vSS = IF ( LEN ( vSeconds ) = 1, "0" & vSeconds, vSeconds )
RETURN
    CONVERT ( vHH & vMM & vSS, INTEGER )
 
Step 4 - change format of new HH:MM:SS measure in the format box to 00:00:00 (have to type this in the box) as in the below - 

 

Step 5 - 

Add HH:MM:SS measure into Y-Axis of chart and Date column into X-Axis.

 

Step 6 - 

Change Y-Axis display units to None as in the below - 

 The result should be something similar to the below - 

Also works with bar charts. Hope this helps anyone struggling with getting time on the Y-Axis.

 

 

 

 

3 Replies

  • mlvdijl's avatar
    mlvdijl
    Frequent Visitor

    Great find! However, the axis isn't quite correct if I apply this solution, as it treats the time as integers it doesn't "stop" at 60, but goes through to 100. For example: a time of 00:18:54 is plotted about halfway between 18 and 19, while it should be very close to the 19 min line. 

     

    After trying out several things including dynamic format string, I still find myself reverting back to using minutes as a decimal number on the axis, and creating a custom tooltip that shows the correctly formatted time.

     

    Very annoying that PowerBi doesn't offer a better solution for this. Please vote for the idea below if you're also looking for this! 

     

    Microsoft Idea

    • RobertDosek's avatar
      RobertDosek
      New Member

      Hello, I agree... What do you mean by "creating a custom tooltip that shows the correctly formatted time"? 

      Thanks

  • mlvdijl's avatar
    mlvdijl
    Frequent Visitor

    Hi RobertDosek. I usually create a second measure and use  FORMAT to show the time as mm:ss. This doesnt work in a chart because its essentially a text value, but you can put it in a table, matrix or card visual and use it as a tooltip on the chart.