3
votes

In Power Bi, I have a table that contains Name and TimeSpent by user in seconds. I want to convert total seconds spent by all users into duration format (hh:mm)

When I am getting seconds in hh:mm format for each user from database query, the values are coming up like these 12:63 etc. After importing these values into power bi, I tried to set its datatype to DateTime format but power bi shows an error saying that it is not a valid value. If I set the datatype of the column as string then strings dont add up.

What can be the ideal way to do it?

5

5 Answers

4
votes

You can try the following DAX:

HHMMSS = 
INT(Table[TimeSpent] / 3600) & ":" &
RIGHT("0" & INT((Table[TimeSpent] - INT(Table[TimeSpent] / 3600) * 3600) / 60), 2) & ":" &
RIGHT("0" & MOD(Table[TimeSpent], 3600), 2)

Source

4
votes

you can solve this in one line:

measure = FORMAT(TIME(0;0;tableNAME[your_column]);"HH:mm:ss")
1
votes

Had a similar question but for D:HH:MM:SS, code below if it's of use.

DurTime (meas) = 
VAR vDur = <<<duration in CALCULATE(SUM(seconds)) >>>
  RETURN INT(vDur/86400) & ":" &                     //Days
    RIGHT("0" & INT(MOD(vDur/3600,24)),2) & ":" &    //Hours 
    RIGHT("0" & INT(MOD(vDur/60,60)),2) & ":" &      //Minutes
    RIGHT("0" & INT(MOD(vDur,60)),2)                 //Seconds
0
votes

That's a better formula, which I'm using in PBI: HHMMSS = FORMAT(TIME(int(Table[TimeSpent] / 3600); int(mod(Table[TimeSpent]; 3600) / 60);int(mod(mod(Table[TimeSpent]; 3600); 60))); "HH:mm:ss")

0
votes

DAX code:

 = TIME(0,0,SUM('Table'[Timespent]))

Then click the modelling tab and choose Format - Date Time and choose the appropriate format.