Search code examples
powerbipowerquerym

PowerQuery to convert a Record into text


Here's something I am needing to do. I am looking to convert a Record into Text/string representation.

For example:-

if a record is

[OrderId = "10001", Owner = "Sam"]

I would like to convert it into a text format like this:

"[OrderId = \"10001\", Owner = \"Sam\"]"

Any help is greatly appreciated!


Solution

  • try this, works for any # of fields

    let x=[OrderId = "10001", Owner = "Sam"] ,
    z="""["&Text.Combine(Table.AddColumn(Record.ToTable(x), "Custom", each [Name]&" = \"""&[Value])[Custom],"\"", ")&"\""]"""
    in z