ICAEW.com works better with JavaScript enabled.
Exclusive

Summarising Vertical Lists Horizontally

Author: Liam Bastick

Published: 08 Aug 2025

Exclusive content
Access to our exclusive resources is for specific groups of students, subscribers and members.

For the second month running, I have an article inspired by recent consulting problems. Obviously, I will change the data! Imagine we have a table called Data (sorry, that’s as far as my imagination goes!) that contains details of some new items and their suppliers in a standard tabular format (i.e. a vertical list), as below. Let’s suppose we need to import this data into an inventory management system.

Screenshot of Excel Spreadsheet
The other Table on the far right we will call Column. However, the system requires a template that only allows one row per item. Therefore, the data needs to be laid out as follows (horizontally and summarised):
Screenshot of Excel Spreadsheet

We need to convert this automatically such that when the data updates, it will be trivia to refresh. Therefore, this month I shall branch out in the wonderful world of Get & Transform (i.e. The Artist Formerly Known As Power Query) in order to transform the structure of the data from the original vertical format to the required horizontal one.

You can download the example file here.

Firstly, we will import the two Tables into Power Query, one by one, by selecting each Table and then navigating to the Data tab, and click ‘From Table/Range’ under the ‘Get & Transform Data’ grouping, viz.

Screenshot of Excel Spreadsheet
Secondly, we need to convert the Column query into a list by going to Transform tab and then selecting ‘Convert to List’.
Screenshot of Excel Spreadsheet
Screenshot of Excel Spreadsheet
Thirdly, we come to the Data table. We rename this query ‘Transformed Table’.
Screenshot of Excel Spreadsheet

We need Power Query to identify a list of grouped columns (i.e. ItemCode and ItemName). To do this, we add a new step by clicking ‘fx’ next to the Formula bar. Then, we will use Power Query’s List.RemoveItems and Table.ColumnNames functions to remove all repeated columns listed in the Column list (which we created earlier) from the Source step. We add the formula below to the Formula bar and name this step as GroupCols.

=List.RemoveItems(Table.ColumnNames(Source),Column)

Screenshot of Excel Spreadsheet

Then, we re-order the columns with the following formula. List.Combine helps combine grouped columns above with the Column list, which has a correct column order for repeated columns.

=Table.ReorderColumns(#“Replaced Value”,List.Combine({GroupCols, Column})

As you can see from the picture below, Note is now the last column:

Screenshot of Excel Spreadsheet
We will next remove all the null values in the table by replacing values null with “”. This ensures that all values are kept after we unpivot shortly (yes, you can do that in Power Query!).
Screenshot of Excel Spreadsheet
Screenshot of Excel Spreadsheet
After that, we need to unpivot the columns, specifically the four [4] repeated columns in our Column list. We simply select the four columns, right click and select ‘Unpivot Columns’.
Screenshot of Excel Spreadsheet

To keep the query dynamic, we need to replace the grouped columns with our variable ‘GroupCols’ from:

= Table.UnpivotOtherColumns(#"Replaced Value", {"ItemCode", "ItemName"}, "Attribute", "Value")

into:

= Table.UnpivotOtherColumns(#"Replaced Value", GroupCols, "Attribute", "Value")

Screenshot of Excel Spreadsheet
We will next group all repeated columns into their respective ItemCode and ItemName. To do this, we select both ItemCode and ItemName columns and go to the Transform Tab, where we select ‘Group By’. We name the new column ‘All’ and choose the operation ‘All Rows’ from dropdown list.
Screenshot of Excel Spreadsheet
Once again, to keep the query dynamic we will replace the values {"ItemCode", "ItemName"} in the formula with GroupCols.
Screenshot of Excel Spreadsheet

We are then going to add an index column in each table within the All column, such that when it reaches a row with new ItemCode and ItemName values, the index resets to one [1]. We then create a new blank step called Indexed and apply the following formula:

= Table.TransformColumns(#"Grouped Rows", {{"All",
each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}})

Screenshot of Excel Spreadsheet
The above formula indexes the All column and is named GroupIndex, with the index starting at one [1] and increases in increments of one [1]. Next, we expand the All column which should then look like the following:
Screenshot of Excel Spreadsheet

While the above indexing would allow us to separate the data based on each item code and name, we would like to further index and separate the data by suppliers as well. First, we need to establish the number of repeated columns or the number of rows per unique supplier, which is four [4]. To do this, we use List.Count function as below:

=List.Count(Column)

We will rename this step as RepeatedCols, and next we use the following formula for a new blank step:

= Table.TransformColumns(#"Expanded All", {{"GroupIndex", each Number.RoundUp(_ / RepeatedCols), type number}})

The above formula rounds up the index column to the closest division of four, e.g. 1/4 = 0.25 rounded up is one [1], 2/4 = 0.5 rounded up is still one [1] etc. Thus, the query will now look like this:

Screenshot of Excel Spreadsheet
We next merge the Attribute and GroupIndex columns to give each supplier an index identifier using ‘Merge Columns’ under the Transform tab. We name the merged column as Columns.
Screenshot of Excel Spreadsheet
Then, we select the column Columns and click ‘Pivot Column’ under the Transform tab. We then choose the column Value as the ‘Values Column’ and click ‘Advanced options’ to select ‘Don’t Aggregate’ for the ‘Aggregate Value Function’.
Screenshot of Excel Spreadsheet
Lastly, we convert “” back to null values using ‘Replace Values’, and finally, ‘Close & Load’. We should have the end result as follows:
Screenshot of Excel Spreadsheet

It may seem like a lot of work, but now, when the data updates, all you have to do is ‘Refresh’.

The Final Friday Fix will return on Friday 27 May 2022 with a new Excel Challenge. In the meantime, please look out for the Daily Excel Tip on our home page and watch out for a new blog every business working day.

Archive and Knowledge Base

This archive of Excel Community content from the ION platform will allow you to read the content of the articles but the functionality on the pages is limited. The ION search box, tags and navigation buttons on the archived pages will not work. Pages will load more slowly than a live website. You may be able to follow links to other articles but if this does not work, please return to the archive search. You can also search our Knowledge Base for access to all articles, new and archived, organised by topic.

Open AddCPD icon