Forum Discussion

SenoirB's avatar
SenoirB
Frequent Visitor
3 years ago
Solved

Convert number with text to number

Hello all, I have a Duration column on a report that I need to transform into total minutes.    The current outputs are a variation of the follow three formats: 15 s 11 m 57 s 2 h 15 m 8 s   I...
  • v-jingzhang's avatar
    v-jingzhang
    3 years ago

    Hi SenoirB 

     

    I modified AntrikshSharma 's solution as below. You can use this code to create a custom column. 

    let result = 
        Text.Replace ( 
            Text.Replace ( 
                Text.Replace ( 
                    Text.Replace ( [Time], " ", "" ), 
                    "h", "*60+" 
                ), 
                "m", "*1+"
            ), 
            "s", "/60" 
        ) 
    in
    if Text.EndsWith(result, "+")
    then Expression.Evaluate(Text.Range(result, 0, Text.Length(result)-1)) 
    else Expression.Evaluate(result)

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.