Formula to create helper column
Hi all! I have a column the includes names. They are not unique, so a name can appear in multiple rows. What I'd like to create is a helper column with an index starting 1,2,3,4, etc. for each name but ONLY if it is the first appearance. If the name already has an index, it should be blank. Something like this:
NAME INDEX
name1 1
name2 2
name1 [blank]
name3 3
How do I create a column formula like that? I did MATCH, which works to create a unique index for the names but it repeats the previous index. I need it to be blank instead. Thanks!
Best Answers
-
Try something like this...
Insert an auto-number column (called "Auto") with no special formatting.
Insert a text/number column (called "Row") with the following column formula:
=MATCH(Auto@row, Auto:Auto, 0)
Then in your INDEX column you can use:
=IF(COUNTIFS(Name:Name, @cell = Name@row, Row:Row, @cell<= Row@row) = 1, COUNT(DISTINCT(COLLECT(Name:Name, Row:Row, @cell<= Row@row))))
-
You could reference the Auto column directly, but it may look a little funny if you end up sorting the sheet or inserting new rows into the middle. It is up to you. Using the Row method means that Name 1 will always be the at the top of your sheet, Name 2 will always be the next one down, etc. regardless of sorting/inserting/adding/deleting the rows.
Answers
-
Try something like this...
Insert an auto-number column (called "Auto") with no special formatting.
Insert a text/number column (called "Row") with the following column formula:
=MATCH(Auto@row, Auto:Auto, 0)
Then in your INDEX column you can use:
=IF(COUNTIFS(Name:Name, @cell = Name@row, Row:Row, @cell<= Row@row) = 1, COUNT(DISTINCT(COLLECT(Name:Name, Row:Row, @cell<= Row@row))))
-
Wow! That works, Paul! I have 20+ years in JavaScript, C++, PHP, VBA, etc. but I couldn't crack this one. Why do I need an additional Row after the Auto? You can't use the Auto in the formula?
-
You could reference the Auto column directly, but it may look a little funny if you end up sorting the sheet or inserting new rows into the middle. It is up to you. Using the Row method means that Name 1 will always be the at the top of your sheet, Name 2 will always be the next one down, etc. regardless of sorting/inserting/adding/deleting the rows.
-
Great, thanks!
-
Happy to help. 👍️
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 140 Industry Talk
- 472 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 497 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!