cancel
Showing results for 
Search instead for 
Did you mean: 

Duration to Seconds Converter

Super User
2113 Views
Super User
Super User

Duration to Seconds Converter

Converts a Text duration in the format HH:MMSmiley FrustratedS to seconds. The measure takes a single input column ([Duration]).

 

Duration2Seconds =

VAR sub = SUBSTITUTE(MAX('Table'[Duration]),":","|")
VAR hours = VALUE(PATHITEM(sub,1))*3600
VAR minutes = VALUE(PATHITEM(sub,2))*60
VAR seconds = VALUE(PATHITEM(sub,3))*1
RETURN hours+minutes+seconds

 

With the appropriate wizard interface and abstraction, this technique could handle any number of levels and a variety of data input formats, as long as those formats are segmented by a common delimiter ([Delimiter]). The interface could parse the string and present an interface for entering the correct conversion factor ([CF#]) for each level. Pseudo-code follows:

 

Conversion = 

VAR sub = SUBSTITUTE(MAX('Table'[Column]),"[Delimiter]","|")

 

VAR level1 = VALUE(PATHITEM(sub,1))*[CF1]
VAR level2 = VALUE(PATHITEM(sub,2))*[CF2]
VAR level3 = VALUE(PATHITEM(sub,3))*[CF3]

...

VAR level# = VALUE(PATHITEM(sub,#))*[CF#]


RETURN level1+level2+level3+...+level#

 


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!