Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Concatenate texts in m - with special characters (?)

Hi all, I am trying to create a maps url in power query starting from Lat-Lon data. This works fine in DAX but I am unable to create a calculated column in m. The error I get is that "https:// etc." cannot be converted to type. For reference here below the code for the custom function.

Can you help me? 

 

= (lat,lon) =>
let
A="https://www.google.com/maps/search/?api=1&query=",
B=",",
lat=Number.toText(lat),
lon=Number.toText(lon),
R1=Text.Combine(A,lat),
R2=Text.Combine(R1,B),
Result=Text.Combine(R2,lon)
in
Result

 

  • Anonymous , you might change some statements this way,

     

    R1=Text.Combine({A,lat}),
    R2=Text.Combine({R1,B}),
    Result=Text.Combine({R2,lon})

    or

    = (lat,lon) =>
    let
    A="https://www.google.com/maps/search/?api=1&query=",
    Lat=Number.toText(lat), //better with a different variable name to avoid ambiguity
    Lon=Number.toText(lon),
    Result=Text.Combine({A,Text.Combine({Lat,Lon},",")})
    in
    Result

     

3 Replies

  • CNENFRNL's avatar
    CNENFRNL
    Icon for Community Champion rankCommunity Champion

    Anonymous , you might change some statements this way,

     

    R1=Text.Combine({A,lat}),
    R2=Text.Combine({R1,B}),
    Result=Text.Combine({R2,lon})

    or

    = (lat,lon) =>
    let
    A="https://www.google.com/maps/search/?api=1&query=",
    Lat=Number.toText(lat), //better with a different variable name to avoid ambiguity
    Lon=Number.toText(lon),
    Result=Text.Combine({A,Text.Combine({Lat,Lon},",")})
    in
    Result

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks CNENFRNL , this fix works great.

    Can you please explain me the need for the {} in the code? I thought being both values "text" it was enough. Thanks

    • CNENFRNL's avatar
      CNENFRNL
      Icon for Community Champion rankCommunity Champion

      Anonymous , according to the syntax

      Text.Combine(texts as list, optional separator as nullable text) as text

      the first parameter should be of type list, which means that all substrings to be combined should be populated into a list, e.g. {Lat, Lon}.

       

      Btw, there's a shorthand for Text.Combine when it comes to 2 substrings,

      #"Combined Texts" = "A" & "B"