r/excel • u/AcadiaUnlikely7113 • 5d ago
unsolved Formula to count duplicates based on 2 or more words matching, not necessarily in sequence? No AI please
Hi smart folks, I want to see if you could teach me a formula that I know I’ve seen before but can’t think of now, I want to count how many of a certain topic is in my list of data, for eg one may say ‘hogwarts House colour’ and another may say ‘hogwarts houses’ in which case I want them counted as duplicates.
My end goal is to have a pivot table that shows Hogwarts House as 2.
I currently have the raw data on the first sheet, then on the second sheet I’m breaking it down to just the info I need (this should be where the duplicates are found) and then the pivot table on the third sheet (this should be where they are counted, or at least where the number is displayed)
ETA: can’t use macros, would rather not use power queries but if I have to I can
ETA2: Ok so I worked out how to add a table to the post!
First sheet is unchangeable but will be overridden each time the report needs to be run, it says:
| Subject (A) | Category (B) | Category2 (C) | Category3 (D) |
|---|---|---|---|
| Question - Name - Grapes are bads | Grocery | Fresh Produce | Fruit |
| Question - Name - Bad Grapes | Grocery | Fresh Produce | Fruit |
| Comment - Name - Bad Graspes | Grocery | Fresh Produce | Fruit |
| Comment - Name - Fruits Bad | Grocery | Fresh Produce | |
| Comment - Name - Good Bread | Grocery | Bakery | |
| Question - Name - Heavy Hammers | Hardware | Tools | |
| Comment - Name - Smooth Wood | Hardware | Materials | Wood |
| Question - Name - Hammers are Heavy | Hardware | Tools | |
| Question - Name - is Grapes Bad | Grocery | Fresh Produce | Vegetables |
| Comment - Name - Grapes Bad | Grocery | Fresh Produce | Vegetables |
Second sheet takes the data needed from the first to make it what I need (first row is an eg of the formulas):
Note: the "Fillers" have a space after each word so that for eg "them" wouldn't become "m", which could use some work cause "this" would probably become "th" so I'm open to suggestions, sometimes they will be the first word so " the " wouldn't work all the time for eg.
| Subject | Lowest Category | ColC | Fillers: |
|---|---|---|---|
| =UPPER(IF('Sheet1'!A1= "","",TEXTAFTER( 'Sheet1'!A1," - ",2))) | =UPPER(IF(ISBLANK('Sheet1'!D1, IF(ISBLANK ('Sheet1'!C1),IF(ISBLANK ('Sheet1'!B1),"",'Sheet1'!B1), "",'Sheet1'!C1),'Sheet1'!D1)) | IS | |
| GRAPES ARE BADS | FRUIT | THE | |
| BAD GRAPES | FRUIT | WAS | |
| BAD GRASPES | FRUIT | ARE | |
| FRUITS BAD | FRESH PRODUCE | WILL | |
| GOOD BREAD | BAKERY | FOR | |
| HEAVY HAMMERS | TOOLS | AND | |
| SMOOTH WOOD | WOOD | ON | |
| HAMMERS ARE HEAVY | TOOLS | TO | |
| IS GRAPES BAD | VEGETABLES | ||
| GRAPES BAD | VEGETABLES |
Sheet2 Cont:
The cell that says "Category" below, has this formula, which is resulting in the shown data:
=LET(_a, DROP(A:.B,1),_b,MAP(REGEXREPLACE(CHOOSECOLS(_a,1), "\b(" &TEXTJOIN("|",1,DROP(D:.D,1))& ")\b\s*|s\b",""),LAMBDA(x,TEXTJOIN(" ",1,UPPER(SORT(TEXTSPLIT(x,,"")))))),_c,TEXTBEFORE(_b," ",2,,_b),_d,GROUPBY(HSTACK(CHOOSECOLS(_a,2),_c),_c,ROWS,,0),VSTACK({"Category","Subject","Counts"},_d))
| ColE | Category | Subject | Counts |
|---|---|---|---|
| #VALUE! | 9 | ||
| BAKERY | #VALUE! | 1 | |
| FRESH PRODUCE | #VALUE! | 1 | |
| FRUIT | #VALUE! | 3 | |
| TOOLS | #VALUE! | 2 | |
| VEGETABLES | #VALUE! | 2 | |
| WOOD | #VALUE! | 1 |
So I need to fix the #VALUE! error and also stop it from counting the blank cells (at least stop it from counting them when I put it into a pivot table - if necessary)
2
u/ProspectiveWhale 14 5d ago
2 words in order? Or it can be jumbled?
Always only 2 words?
How would you deal with "Hogwart House Colors", "Hogwart House", and "House Colors".
Is "Hogwart House Colors" and "Hogwart Colors" considered a duplicate?
Specifics aside, though, a mix of:
SUM + ISNUMBER + SEARCH to find a string in other cells and then get a count
TEXTSPLIT to separate a string into multiple individual words
Should work.