Forum Discussion

wseef's avatar
wseef
New Member
5 years ago
Solved

Display JSON array as column in Power Query

I'm new to power query. I'm parsing JSON. I have an array name as "categories" when I expand it using Power Query it creates three rows for each category while I just want to remain in one row and wa...
  • edhans's avatar
    5 years ago

    wseef - you want to extract to values. See this code:

     

    let
        Source = #table(1,{{{1..3}}}),
        #"Extracted Values" = Table.TransformColumns(Source, {"Column1", each Text.Combine(List.Transform(_, Text.From), ":"), type text}),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3"})
    in
        #"Split Column by Delimiter"

     

    That has a list of 1, 2, and 3.

    Press the Extract to Values and pick a delimiter. I picked the colon.

    You get this:

     

    Then simply select that column and on the home ribbon of Power Query, Split Columns, and set it as follows:

    You get this:

    How to use M code provided in a blank query:
    1) In Power Query, select New Source, then Blank Query
    2) On the Home ribbon, select "Advanced Editor" button
    3) Remove everything you see, then paste the M code I've given you in that box.
    4) Press Done
    5) See this article if you need help using this M code in your model.