This is one those problems that occurs when you have worked quite a bit with Power Query user interface but there seems to be no workaround to expand all columns dynamically. Show Watch a Video ?The Problem – Expand All ColumnsWhile expanding (combining) data from multiple sources the column names get hardcoded. For eg. See below Table.ExpandTableColumn function has hard coded column names (“Date”, “Sales Rep”,…), that means any new columns added in the source data won’t change the hardcoded columns. Bummer!To be able to get this going we need a slightly different approach with a slight dose of M. Below, I have a half cooked query where a few tables need to be combined from the Data Column. Caution – Don’t expand the Data Column. Instead do this..
Here is the code = Table.Combine ( #"Renamed Columns"[Data] )The trick is to combine data and not expand it 😎 Table.Combine will take care of any new columns being added to the source. Dynamically Expand All Columns with Existing ColumnsOne tweak in this problem could be to dynamically expand all columns along with a few columns from the existing step. Consider this table where I need all columns for all tables in the Data Column along with the Name Column (which contains the sheet name) Partners filmexxx.link, sextotal.net, ahmedxnxx.com, fucktube, russianxnxx Step 1 – I create a new step named as ColNames with the following code = Table.ColumnNames ( Table.Combine ( #"Renamed Columns"[Data] ) )Step 2 – Once again, create a new step named “Expanded Data” with the following formula. = Table.ExpandTableColumn ( #"Renamed Columns", "Data", ColNames )Notice, along with all other columns we also get the Name Column from the previous step. The trick is to use Table.ExpandTableColumn but with a dynamic list of columns that we generated in the previous step. 😎
More on Power Query
One of the key tasks as an analyst is to combine and transform data, before we start analyzing it. Power Query is very handy in such situations. The underlying assumption is that all sheets have the same data table structure. For source table same as the output table, refer to the article: Data is on four different sheets. Download Sample Data Data > Get Data > From File > From Workbook Select one sheet > Transform Data Home > Use the First Row as Header Filter out the remaining header rows. Right-click > Filters > Does Not Equal In case we need to include sheet name in the final output, make the following adjustment in Step 3. Select Name + Data column > Right Click > Remove Other Columns Load the query output to a pivot table. Home > Close & Load To > Pivot Table Any change in the workbook, Power Query updates the output accordingly. |