Power Query: Create row number for each group in Excel
Have you ever tried to create sequence row number for each group in Excel worksheet as below screenshot shown? Normally, you can create a formula to solve this task. But, in this article, I will introduce how to deal with this job by using the Power Query in Excel.
To generate the index numbers for each group of the data, the Power Query can do you a favor. Please do with the following steps:
1. Select the data range that you want to insert the row number. In Excel 2019 and Excel 365, click Data > From Table/Range, see screenshot:
Note: In Excel 2016 and Excel 2021, click Data > From Table, see screenshot:
2. In the Create Table dialog box, click OK button to create a table, see screenshot:
3. And then, in the opened Power Query Editor window, select the column that you want to use to group the table, then right click it. And then, choose Group By from the context menu, see screenshot:
4. In the Group By dialog box:
- Select the column name that you want to insert the row number based on from the drop-down list;
- Select All Rows option from the Operation drop-down list;
- Click OK button.
5. Now, return to the Power Query Editor window, click Add Column > Custom Column, see screenshot:
6. In the Custom Column dialog box, using the Table.AddIndexColumn function as below screenshot show:
- Type a new column name into the New column name text box;
- Then, enter this formula: =Table.AddIndexColumn([Count],"Index",1) into the Custom column formula box;
- At last, click OK button.
Note: In the above formula, [Count] is the name of the column you have created in step 4, please change it to your need.
7. Now, return to the Power Query Editor window, you should remove all other columns and only keep the last column you have created. Right click the last column name you are created, select Remove Other Columns, see screenshot:
8. Then, expand this column, click the Expand icon next to the column title. In the expanded box, check Expand option, and then check all the column names from the list box, and uncheck the Use original column name as prefix option. And finally, click OK button. See screenshot:
9. And now, you can see the row index numbers are displayed as below screenshot shown:
10. Then, please click Home > Close & Load > Close & Load to load the data into a new worksheet, see screenshots:
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!