Creating a count within groups of rows

Hello


I am trying to create SKU codes for products depending on their design. The general format of the SKU code I am looking for is SKUxxyyy. Where xx = 01 to 26 where the first letter of the design begins with A, B, C etc. to Z. The yyy = 001 for the first design in each letter, 002 for the second etc.


Before I go too far down this rabbit hole I wondered if anyone had any experience of this or ideas I could try.


Thanks in advance,

Tim

MacBook Pro 13″, macOS 10.13

Posted on Dec 11, 2020 7:07 AM

Reply
4 replies

Dec 11, 2020 10:55 AM in response to Badunit

One other note: It is a little scary relying on formulas for these SKU numbers. You should keep good backups in case something goes amiss.


You could, from time to time, select all the SKU numbers that have been made to date (or just those still using the formula), Copy, then Paste Formula Results back to the same cells to "lock them in". Then, even if something happens, at least those ones are locked in.

Dec 11, 2020 3:54 PM in response to timmcg23

If doing it manually, you can add a column to check for duplicates, which might happen when doing it manually.


If the SKUs are in column B,

=IF(COUNTIF(B,B)>1,"DUPLICATED", "")


This will flag any duplicates for you to correct. It flags the original and any/all duplicates.


If you use the formula method to create the SKU, you can include a column that tells you to lock in the results. This might be easier than typing in a SKU; you are given the SKU and all you have to do is lock it in. Create a simple keyboard shortcut for Paste Formula Results and all it will take is Cmd C (copy) followed by your new shortcut. This does require, though, that you not change any SKUs afterward or manually enter any that are out of order. That would break the formula that comes up with the next SKU.


G2 =IFERROR(IF(AND(C2, FORMULATEXT(F2)<>""),"Remember to Lock in the SKU!", ""), "")


Just some thoughts. It does get complicated. It may be better to manually enter them and use the formula to flag duplicates.

Dec 11, 2020 10:47 AM in response to timmcg23

This can be done. There is more than one set of formulas that will do it. One is presented below. Simpler formulas may be posted by others later, more than likely.


Formulas are often simpler and easier to debug if the problem is split into parts vs trying to do too much in one cell. For that reason, I added a few columns to your table, all of which can be hidden later. Note that, with formulas vs manually entered SKU numbers, you have to be aware of what sorting might do to your SKU numbers. You don't want everything renumbering itself as a result of the sort. I designed the formulas below so that the table could be sorted.



Column A, the Index Number column, is actual numbers, not formulas. I added this to make the table sortable without all your SKU numbers changing. You will see it in the formula for the "design number". You can keep adding numbers at the bottom but always keep increasing it, never skip a row and fill it in later, and never renumber a row that already has a product and a SKU number.


Column C just checks if there is a valid product name in column B. Only words that begin with A-Z (upper case only) are allowed. I used the ASCII codes for this check. This result is used in the other formulas. If the name is valid, the other formulas will come up with the SKU, otherwise they will not.


C=IFERROR(AND(CODE(B)>64, CODE(B)<91),FALSE)


Column D, the design code, turns the first letter of the product name into a number. It appends a "0" to the front (for single digit results) but then truncates the result to the 2 rightmost characters (for two-digit results).


D =IF(C,RIGHT("0"&(CODE(B)−64),2),"")


Column E, Design Number, uses the index in column A to determine which design number this product will get.

It counts how many rows have the same Design Code (column D) and a lower index number (column A). Actually the second check is "less than or equal to" and it counts the current row so the answer will be at least 1.


E =IF(C,RIGHT("00"&COUNTIFS(D,D,A,"<="&A),3),"")


Column F puts it all together


F =IF(C,"SKU"&D&E,"")

Dec 11, 2020 2:37 PM in response to Badunit

Thank you Badunit. First of all for your solution to my SKU question. But also for making me think about the practicality of using a formula to set the SKU's in the first place. I think you are right that there is a risk of overwriting them or getting in a mess when sorting or changing products. For this reason I've decided to go down the manual route for now ( I have less than 200 products at the moment) as if feels safer.


Thanks

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Creating a count within groups of rows

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.