• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Add Column with Grouping Order|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Add Column with Grouping Order|Power Query|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryAdd Column with Grouping Order
sp_PrintTopic sp_TopicIcon
Add Column with Grouping Order
Avatar
ExcelNovice2020
Member
Members
Level 0
Forum Posts: 62
Member Since:
February 8, 2020
sp_UserOfflineSmall Offline
1
April 2, 2023 - 5:06 am
sp_Permalink sp_Print

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.  

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 648
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
April 3, 2023 - 6:52 pm
sp_Permalink sp_Print

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?

Avatar
ExcelNovice2020
Member
Members
Level 0
Forum Posts: 62
Member Since:
February 8, 2020
sp_UserOfflineSmall Offline
3
April 4, 2023 - 11:02 pm
sp_Permalink sp_Print

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.  

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 648
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
4
April 4, 2023 - 11:18 pm
sp_Permalink sp_Print

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"

Avatar
ExcelNovice2020
Member
Members
Level 0
Forum Posts: 62
Member Since:
February 8, 2020
sp_UserOfflineSmall Offline
5
April 7, 2023 - 11:32 pm
sp_Permalink sp_Print

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

Thank you for the help.  

Avatar
ExcelNovice2020
Member
Members
Level 0
Forum Posts: 62
Member Since:
February 8, 2020
sp_UserOfflineSmall Offline
6
April 7, 2023 - 11:55 pm
sp_Permalink sp_Print

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). 

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.