PowerQuery: How can I concatenate grouped values?

前端 未结 2 2063
甜味超标
甜味超标 2020-11-28 05:08

If I have the following table (shown in the image below), how can I write a grouped query that would concatenate the grouped results?

For this example, I\'d

2条回答
  •  时光取名叫无心
    2020-11-28 05:40

    If your table is Source, and if NumberColumn has the number type, then this will work:

    = Table.Group(Source, {"LetterColumn"}, {{"Column", each Text.Combine(List.Transform(_[NumberColumn], (x) => Number.ToText(x)), ","), type text}})

    Table.Group does a group by operation, which creates a table made up of all of the rows with the same value in LetterColumn. _[NumberColumn] gives a list of the values in the NumberColumn column in this new table. The List.Transform part turns the numbers into text values, and Text.Combine joins those numbers together, with a comma separating each value.

    If you need the surrounding quotes as well, you can do this:

    = Table.Group(Source, {"LetterColumn"}, {{"Column", each """" & Text.Combine(List.Transform(_[NumberColumn], (x) => Number.ToText(x)), ",") & """", type text}})

    """" represents the " character, and & combines two text values.

提交回复
热议问题