powerbipowerquerypowerbi-desktopm

How to add or insert ' (single quotes) for every string in a list in which strings are separated by commas in Power Query


I have a table #"DistinctCompanyCode" with only 1 column [Company Code]

In PowerQuery, I was able to get it into a string

= Text.Combine(List.Buffer(#"DistinctCompanyCode"[Company Code]), ",")

Where the result becomes 123,456,789

My question is, how can I make it to have single quote at the beginning and end of the "str"

Desired result to be '123','456','789' so that I can use this to put in the IN sql statement


Solution

  • you can try something like below

    = [a= DisctinctCompanyCode[Company Code],
    b=List.Transform(a,each "'"&_&"'"),
    c=Text.Combine(List.Buffer(b), ",")][c]
    

    enter image description here