I want to expand all lists and records in a json response. Columns are like e.g. (this is dynamically, it also can be 10 records and 5 lists):
Text, Text, [List], [L
Assuming that the previous step in M was named Removed Other Columns
, and that the column to expand is named Data
, then I replace the line with #"Expanded Data"
with the following code:
#"Expanded Data" =Table.ExpandTableColumn(#"Removed Other Columns", "Data", List.Union(List.Transform(#"Removed Other Columns"[Data], each Table.ColumnNames(_))))
It dynamically adapt to any column names.
Chris Webb wrote a function to do this for Table-type columns:
http://blog.crossjoin.co.uk/2014/05/21/expanding-all-columns-in-a-table-in-power-query/
I've shared a tweaked version of that that I made for Record-type columns:
https://gist.github.com/Mike-Honey/0a252edf66c3c486b69b