Flatten Rows in a Table for a Listbox

Qwest336

Board Regular
Joined
Jun 24, 2015
Messages
53
Hello everyone!

I have been trying to find a way to do this for a while now and I can't come up with anything good. As always, any help pointing me on the right path would be greatly appreciated.

What I need to do is to flatten multiple rows into one row, keeping non-empty cells in specific columns. For example, given the following recordset:
Player,Carries,Rushing Yards, Rushing TDs,Receptions,Receiving Yards,Receiving TDs
R1: Joe Jones,100,425,3,,,
R2: Joe Jones,,,,12,45,0

I would like to produce the following single row:

R1: Joe Jones,100,425,3,12,45,0

The only real difference is the data for merge is not numerical, it's textual.

I currently have the data in a table that I've loaded to the worksheet from PQ. The best solution would be one where I perform the merge operation in PQ/M-code prior to the table load as I'm filtering/loading a listbox on a userform from that worksheet. The next best solution would be to copy the data from the filtered table into a separate worksheet and then perform the merge operation prior to loading it into the Listbox on the Userform.

I wish I had some examples of what I have tried but I really haven't even gotten close yet. I almost got there using a Pivot Table and the Max operation, but the actual values, as mentioned, are textual in nature so they don't play well in the value section of a Pivot.

I'm using Excel 2013, 32bit.

Any thoughts?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hello all,

I was able to finally find a method to flatten the table using PowerQuery and adapt it for my needs! For anyone that is looking, here's the link I used.

User "ImkeF" provided the following M-Code:

Code:
let
    Source = YourTable,
    #"Grouped Rows" = Table.Group(Source, {"YOURCOMMONFIELDNAME"}, {{"FillUp", each Table.FirstN(Table.FillUp(_,Table.ColumnNames(_)), 1), type table}}),
    #"Expanded FillUp" = Table.ExpandTableColumn(#"Grouped Rows", "FillUp", List.Skip(Table.ColumnNames(Source),1), List.Skip(Table.ColumnNames(Source),1))
in
    #"Expanded FillUp"
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top