Forum Discussion

vsatamraju's avatar
vsatamraju
Microsoft Employee
9 years ago

splitting the url based on condition


Hi Team,

 

I need to show the data from different tables and among them url is one fof the column. Actually i am splitting the column (that is url column) by "/" .but some times if "/" is not present in the url ,it is showing the column as blank.

 

My issue is splitting the url based on some condition .

I need to split the url based on the top most right one.if that is not present it should not split.

 

example 1: http://microsoft.com/en-us
in this case result should show the en-us

 

example 2: http://microsoft.com
in thi case result should show complete url like http://microsoft.com

 

Thanks in advance.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Rather than using the split columns method, I'd recommend writing a custom column to check conditions and copy the appropriate string.

  • Hi, this "M" code could help you to achieve.

     

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyigpKbDS188sT87XS87XT0xKVorVQRdWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","//","||",Replacer.ReplaceText,{"Column1"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value","Column1",Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv),{"Column1.1"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}}),
    #"Replaced Value2" = Table.ReplaceValue(#"Changed Type1","||","//",Replacer.ReplaceText,{"Column1.1"})
    in
    #"Replaced Value2"

     

    Regards