Forum Discussion

jereaallikko's avatar
jereaallikko
Helper III
6 years ago
Solved

How to simplify a column text

Hi all,   I'm having a slight problem with organizing a messy data table, in Power BI Query. An example table shown below.                             What I'm trying to do (pr...
  • Smauro's avatar
    6 years ago

    Hi jereaallikko 

     

    You could try adding in a function with the transformations, and transforming your column with it:

     

     

        StatFinder = (t1 as text) =>
            let
                t = Text.Replace(Text.Lower(t1), ":", " "),
                s1 = Text.AfterDelimiter(t, "status"),
                n1 =
                    if s1 <> ""
                        then    
                            let t2 = Text.BeforeDelimiter(s1, "%"),
                                t3 = try Number.From(t2) otherwise try Number.From(Text.BeforeDelimiter(Text.AfterDelimiter(Text.Trim(s1), " "), " ")) otherwise null
                            in Text.From(t3)
                        else null,
                res = if n1 = null then "Status: Unknown" else Text.Trim("Status: " & n1 & "%")
            in
                res,
        FindStatus = Table.TransformColumns(PreviousStep,{{"Description",  StatFinder, type text}})

     

     

     (PreviousStep should be your last step)

     

    Cheers,