Need to combine a number of rows in a file based on certain conditions

Cantrecallmyusername

Board Regular
Joined
May 24, 2021
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a large file which has a number of rows which I wish to combine into a smaller number based on certain conditions.
The data in column A is the key piece of information and is duplicated within the report but some of the other rows are split out with data tags which I wish to represent in one column.

The below is a example of my data set - the top three rows are condensed into 1 row which is based on the value of column b.
There will be a different amount of variables in the columns to the right of B and I would like a macro to loop through my file which will have ~2k rows each time

I hope this makes sense and appreciate your help with this one.

1656432389535.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
One way using Power Query.

Book1 (version 1).xlsm
ABCDEFGHI
1Column1Column2Column3Column4Column5Column6Column7Column8Column9
2Test DataTest DataBusiness GlossaryMissing_xyzBusiness GlossaryTest DataBusiness GlossaryData is Great50Under ReviewThis a a larger text field
3Test DataTest DataBusiness GlossaryMissing_abcBusiness GlossaryTest DataBusiness GlossaryData is Great50ReviewedThis a a larger text field
4Test DataTest DataBusiness GlossaryIncomplete_xyzBusiness GlossaryTest DataBusiness GlossaryData is Great50Under ReviewThis a a larger text field
5
6Column1Column2Column3Column4Column5Column6Column7Column8Column9
7Test DataTest DataBusiness GlossaryMissing_xyz Missing_abc Incomplete_xyzBusiness GlossaryTest DataBusiness GlossaryData is Great50Under Review ReviewedThis a a larger text field
Sheet7


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    Group = Table.Group(Source, {"Column2"}, {{"Count", each _, type table [Column1=text, Column2=text, Column3=text, Column4=text, Column5=text, Column6=text, Column7=number, Column8=text, Column9=text]}}),
    CN = Table.ColumnNames(Source),
    Result = Table.TransformColumns(Group,{{"Count", (tr)=> List.Accumulate(CN,Source, (state,current) => Table.Distinct(Table.TransformColumns(state, {{current, each Text.Combine(List.Distinct(List.Transform(Table.Column(state,current),Text.From)),Character.FromNumber(10))}})))}}),
    Expand = Table.ExpandTableColumn(Result, "Count", {"Column1", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9"}, {"Column1", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9"}),
    Reorder = Table.ReorderColumns(Expand,CN)
in
    Reorder
 
Upvote 0
One way using Power Query.

Book1 (version 1).xlsm
ABCDEFGHI
1Column1Column2Column3Column4Column5Column6Column7Column8Column9
2Test DataTest DataBusiness GlossaryMissing_xyzBusiness GlossaryTest DataBusiness GlossaryData is Great50Under ReviewThis a a larger text field
3Test DataTest DataBusiness GlossaryMissing_abcBusiness GlossaryTest DataBusiness GlossaryData is Great50ReviewedThis a a larger text field
4Test DataTest DataBusiness GlossaryIncomplete_xyzBusiness GlossaryTest DataBusiness GlossaryData is Great50Under ReviewThis a a larger text field
5
6Column1Column2Column3Column4Column5Column6Column7Column8Column9
7Test DataTest DataBusiness GlossaryMissing_xyz Missing_abc Incomplete_xyzBusiness GlossaryTest DataBusiness GlossaryData is Great50Under Review ReviewedThis a a larger text field
Sheet7


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    Group = Table.Group(Source, {"Column2"}, {{"Count", each _, type table [Column1=text, Column2=text, Column3=text, Column4=text, Column5=text, Column6=text, Column7=number, Column8=text, Column9=text]}}),
    CN = Table.ColumnNames(Source),
    Result = Table.TransformColumns(Group,{{"Count", (tr)=> List.Accumulate(CN,Source, (state,current) => Table.Distinct(Table.TransformColumns(state, {{current, each Text.Combine(List.Distinct(List.Transform(Table.Column(state,current),Text.From)),Character.FromNumber(10))}})))}}),
    Expand = Table.ExpandTableColumn(Result, "Count", {"Column1", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9"}, {"Column1", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9"}),
    Reorder = Table.ReorderColumns(Expand,CN)
in
    Reorder
Thanks for the reply but power query is not an option for me, was hoping to achieve this with a macro.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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