Forum Discussion

tgjones43's avatar
tgjones43
Helper IV
4 years ago
Solved

Split/extract text after different delimiter

Hi all

 

I have data that looks like the first column below. I'd like to extract the < and > symbols to one column and the numbers to a different column. I think I know how to do this using several queries but is it possible to do with just one query?

 

My DataSignValue
7 7
7.2 7.2
<7<7
<7.2<7.2
>7>7

 

Thank you!

  • Anonymous's avatar
    Anonymous
    4 years ago

    HI tgjones43,

    You can refer to the following code to add two custom columns in the query editor to achieve your requirement:

    #"Added Custom" = Table.AddColumn(Source, "Sign", each if Value.FromText([My Data]) is text then Text.Start([My Data],1) else "")
    
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Value", each if Value.FromText([My Data]) is text then Value.FromText( Text.RemoveRange([My Data],0,1)) else Value.FromText([My Data]))

    Full query:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMleK1QGSekZgOqbUwMA42RyZjSyTCpSJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"My Data" = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Sign", each if Value.FromText([My Data]) is text then Text.Start([My Data],1) else ""),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Value", each if Value.FromText([My Data]) is text then Value.FromText( Text.RemoveRange([My Data],0,1)) else Value.FromText([My Data])),
        #"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Sign", type text}, {"Value", type number}})
    in
        #"Changed Type"

    Regards,
    Xiaoxin Sheng

3 Replies

    • tgjones43's avatar
      tgjones43
      Helper IV

      amitchandak thanks for the quick reply. I tried that but I can't get it to work. Because some of my values have a decimal point and some don't it doesn't work. Can you advise?

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI tgjones43,

    You can refer to the following code to add two custom columns in the query editor to achieve your requirement:

    #"Added Custom" = Table.AddColumn(Source, "Sign", each if Value.FromText([My Data]) is text then Text.Start([My Data],1) else "")
    
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Value", each if Value.FromText([My Data]) is text then Value.FromText( Text.RemoveRange([My Data],0,1)) else Value.FromText([My Data]))

    Full query:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMleK1QGSekZgOqbUwMA42RyZjSyTCpSJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"My Data" = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Sign", each if Value.FromText([My Data]) is text then Text.Start([My Data],1) else ""),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Value", each if Value.FromText([My Data]) is text then Value.FromText( Text.RemoveRange([My Data],0,1)) else Value.FromText([My Data])),
        #"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Sign", type text}, {"Value", type number}})
    in
        #"Changed Type"

    Regards,
    Xiaoxin Sheng