Forum Discussion

Praveen6245's avatar
Praveen6245
New Member
3 years ago
Solved

Possible Approach

Hi community,   I have a requirement where I need to pivot (kind of) a table with column having stacked values. Its like this: ------------------------------ Product name | Ingredients ---------...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Praveen6245 ,

     

    You can copy my code and paste it into advanced editor.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRciwoyEnVUQjOT0nUUQjLzEtNTyxSitWJVnJxdQNKQ0WACkqKEsuTUouKKiGKwWp8fP2AanwT89LzsRkREBgElPbIz0sFagKrUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product name " = _t, Ingredients = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product name ", type text}, {"Ingredients", type text}}),
        #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Ingredients", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Ingredients"),
        #"Replaced Value" = Table.ReplaceValue(#"Split Column by Delimiter"," ","",Replacer.ReplaceText,{"Ingredients"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Ingredients", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type1", {"Ingredients"}, {{"Count", each Table.RowCount(_), Int64.Type}})
    in
        #"Grouped Rows"

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.