Forum

Add Column with Gro...
 
Notifications
Clear all

Add Column with Grouping Order

6 Posts
2 Users
0 Reactions
153 Views
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

I have one column of input with each set of data (two rows each) separated by an empty row.  What is the best way to add a 2nd column showing the separate groups?  For example:

 

Name

A

A

 

B

B

 

Should like:

Name     Group

A             1

A             1

 

B             2

B             2

 

I have also attached an example file.  

 
Posted : 02/04/2023 3:06 pm
(@debaser)
Posts: 837
Member Moderator
 

Hi,

A couple of questions if I may:

Does it actually matter what the group numbers are, as long as the grouping works?

Also, do you actually want the blank rows in the output table?

 
Posted : 04/04/2023 4:52 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

Thank you for helping.

The group number does not matter as long as each two are paired together.  And, I keep the blank row to show separation from each group.  This is a match schedule and the final display will be 20 individual matchups so I keep the blank row between each match for clarity.  

 
Posted : 05/04/2023 9:02 am
(@debaser)
Posts: 837
Member Moderator
 

You could do something simple like this then:

 

let
Source = Excel.CurrentWorkbook(){[Name="Matchups"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Team", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Grouper", each if [Team] = null then [Index] else null),
#"Filled Up" = Table.FillUp(#"Added Custom",{"Grouper"}),
#"Removed Columns" = Table.RemoveColumns(#"Filled Up",{"Index"}),
#"Added Custom1" = Table.AddColumn(#"Removed Columns", "GroupNumber", each if [Team] = null then null else [Grouper]),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Grouper"})
in
#"Removed Columns1"

 
Posted : 05/04/2023 9:18 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

Okay, I see what you did here; I can follow every step.  Yeah, that works.  Just "got stuck."   

Thank you for the help.  

 
Posted : 08/04/2023 9:32 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

My apologies, I spoke too soon.  With regard to the last group, after #"Added Custom" = Table.AddColumn(#"Added Index", "Grouper", each if [Team] = null then [Index] else null), both are null.  Thus, the next command, Table.FillUp, is filling up a null (no number). 

 
Posted : 08/04/2023 9:55 am
Share: