PowerQuery グルーピング

参考サイト

exceltown.com

手順

user.json file.

入力ファイル

[
  {
    "id": 1,
    "name": "sato",
    "sex": "m",
    "old": "30",
    "city": "tokyo"
  },
  {
    "id": 2,
    "name": "kako",
    "sex": "m",
    "old": "30",
    "city": "osaka"
  },
  {
    "id": 3,
    "name": "mina",
    "sex": "w",
    "old": "30",
    "city": "tokyo"
  }
]

PowerQueryによりJSONを読み込みグループ化

ソース

= Json.Document(File.Contents("C:\Users\xxxx\power-query\user.json"))

テーブルに変換

= Table.FromList(ソース, Splitter.SplitByNothing(), null, null, ExtraValues.Error)

展開されたColumn1

= Table.ExpandRecordColumn(テーブルに変換済み, "Column1", {"id", "name", "sex", "old", "city"}, {"Column1.id", "Column1.name", "Column1.sex", "Column1.old", "Column1.city"})

グループ化された行

= Table.Group(#"展開された Column1", 
        {"Column1.sex"}, 
        {
            {"Column1.name", each Text.Combine([Column1.name], ","), type text },
            {"Column1.city", each Text.Combine([Column1.city], ","), type text },
            {"カウント", each Table.RowCount(_), Int64.Type} 
        }
    )