I am looking for an excel forumla that will search the text in a cell and return the location specified in an additional sheet if a match is found.
I have a sheet with the following columns
| item | location | numbers |
|--------|------------|---------|
| apple | washington | 1234 |
| pear | wisconsin | 567 |
| orange | california | 890 |
And another sheet with the following columns:
| item_name | location |
|---------------------|----------|
| super juicy pears | |
| fresh golden apples | |
| apples from wa | |
What I want to do is search the text and display the location. Assume each fruit only has one state.
Note that I looked around on here and only found an unanswered question found here:
Excel Match & Return Values
In Google sheets try:
=ARRAY_CONSTRAIN(FILTER(Sheet1!$B$2:$B$4,REGEXMATCH(A2,Sheet1!$A$2:$A$4)),1,1)
Sheet1!$B$2:$B$4 is location
Sheet1!$A$2:$A$4 is item
Edit
To make search case insensitive:
=ARRAY_CONSTRAIN(FILTER(Sheet1!$B$2:$B$4,REGEXMATCH(A2,"(?i)"&Sheet1!$A$2:$A$4)),1,1)
Related
I have two excel files; the original file contains 10K+ patient names and medical condition, the goal is to identify patients (about 400+) with special conditions so that the mail that gets sent to them is different than the rest of the list.
Original File Template:
Last Name
First Name
Diagnosis
Doe
John
Cancer
Smith
John
HIV
Smith
Jayne
Broken Arm
Rock
Dwayne
Common Cold
Foster
Jane
Common Cold
Mailing Template:
Last Name
First Name
Type of Mail
Doe
John
Smith
John
Smith
Jayne
Rock
Dwayne
Foster
Jane
In the Mailing Template, I want to classify the Type of Mail based on the diagnosis. Common diagnosis would be "LV1" and anything that I would identify as a special diagnosis, like cancer or HIV, would be "LV2"
My initial approach would be to filter the Original File by the special diagnosis and then use a True/False condition of that filtered list against the Mailing template and manually flag LV1 or LV2. But is there a method or formula that could scan the Original File to look for the keywords (eg cancer and HIV) and automatically assign the corresponding names in the Mailing List with "LV1" or "LV2"?
I believe if you can cover all the cases you're interested in, it's possible with a IF(OR) statement, for example:
Let's say B5 is the cell with the diagnosis, in your target cell (where you want "LV1" or "LV2" to appear) you will write the next formula:
=IF(OR(B5="Common*", B5="Broken*"), "LV1", "LV2")
Note the "*" in the diagnosis condition text, it will allow any cell that begins with such text to be considered true. For example, "Common*" will consider both "Common Cold" and "Common Fever" as "LV1" cases.
This solution may be problematic if you have a lot of different diagnoses to cover.
Exact Matches
If you expect to add additional condition/mailing types down the road, =XLOOKUP() would be a good option.
In column D this would match the diagnosis to a set of values in column F, and return the value in column G.
You can add as many diagnosis/mailing type values as you need without changing formulas.
In cell D2: =XLOOKUP(C2,F:F,G:G):
| | A | B | C | D | E | F | G |
|---+-----------+------------+-------------+----------------------+---+-------------+-------|
| 1 | Last Name | First Name | Diagnosis | Type of Mail | | Match | Index |
| 2 | Doe | John | Cancer | =XLOOKUP(C2,F:F,G:G) | | Cancer | LV2 |
| 3 | Smith | John | HIV | LV2 | | HIV | LV2 |
| 4 | Smith | Jayne | Broken Arm | LV1 | | Broken Arm | LV1 |
| 5 | Rock | Dwayne | Common Cold | LV1 | | Common Cold | LV1 |
| 6 | Foster | Jane | Common Cold | LV1 | | | |
Note =XLOOKUP() uses the same concept as using =INDEX(G:G, MATCH(C2, F:F, 0)) in previous versions of excel (and produces identical results).
Wildcard Matching
To support using keywords, you would then need to set the [match_mode] argument in =XLOOKUP() equal to 2, which adds the ability to use wildcards (eg * and ?).
The following would match any diagnosis where the first word matches any first wordcommon using common*.
In cell D2: =XLOOKUP(LEFT(C2, IFERROR(SEARCH(" ", C2)-1, LEN(C2)))&"*",F:F,G:G,0,2)
| | A | B | C | D | E | F | G |
|---+-----------+------------+-----------------+-------------------------------------------------------------------------+---+------------+----------------|
| 1 | Last Name | First Name | Diagnosis | Type of Mail | | Match | Index |
| 2 | Doe | John | Cancer | =XLOOKUP(LEFT(C2, IFERROR(SEARCH(" ", C2)-1, LEN(C2)))&"*",F:F,G:G,0,2) | | Cancer | LV2 |
| 3 | Smith | John | HIV | LV2 | | HIV | LV2 |
| 4 | Smith | Jayne | Broken Arm | LV1 | | Broken Arm | LV1 |
| 5 | Rock | Dwayne | Common Cold | Matches Common | | Common | Matches Common |
| 6 | Foster | Jane | Common Anything | Matches Common | | | |
You would need to adjust some in the event there is crossover in keywords or to search for multi-word keyword, but this should be a good place to start.
I have a spreadsheet like so:
| A | B | C |
|------|---|----------------|
| Bob | | Mary is Nice |
| Mary | | Tim is happy |
| Tim | | Bob is awesome |
and I'm trying to use Excel to find the name values in column A and match the content in column C and then match the output in column B like so:
| A | B | C |
|------|----------------|----------------|
| Bob | Bob is awesome | Mary is Nice |
| Mary | Mary is Nice | Tim is happy |
| Tim | Tim is happy | Bob is awesome |
I'm not sure if there is a formula that can find, match, and sort into column B out of the box. Or if I would need to write a macro. I've been looking and the only thing I can find so far is a match based of a specific value and move it into a seperate worksheet.
I can do this with PHP/MySQL, but that's not the intended result, obviously.
Also, maybe something easier to do within Google Sheets instead?
Use INDEX/MATCH with wild cards:
=INDEX(C:C,MATCH("*"&A1&"*",C:C,0))
OR
VLOOKUP:
=VLOOKUP("*"&A1&"*",C:C,1,FALSE)
I am looking for a way to extract all unique combinations from a number of Excel sheets with multiple columns. E.g.:
#no. | fruit | city | year | something else
1 | apple | London | 2015 | some text
2 | banana | London | 1999 | no text
3 | apple | Oxford | 1895 | some text
4 | banana | London | 1999 | no text
How can I get a list of all unique rows (except for column 1 of course) with any function in Excel or VBA? Preferably it is a script-like way, because the sheets contain over 6000 rows of varying information.
Any thoughts?
If you would like to do it with just formulas, here is some simple steps:
1) Add column at the end of table. In this column, concenate all rows like this:
#no. | fruit | city | year | something else|
1 | apple | London | 2015 | some text |=B2&C2&D2&E2
2 | banana | London | 1999 | no text |
3 | apple | Oxford | 1895 | some text |
4 | banana | London | 1999 | no text |
2) Then add another column to count and numerate occurences of dublicates. Put COUNTIF() formula and fill down:
no | fruit | city | year | something else| Column F |
1 | apple | London | 2015 | some text |=B2&C2&D2&E2|=COUNTIF($F$2:F2,F2)
2 | banana | London | 1999 | no text |
3 | apple | Oxford | 1895 | some text |
4 | banana | London | 1999 | no text |
If you filter last column with criteria=1 you can get all unique rows.
I have an Excel column that cannot be sorted and for which I need to create a unique id by group, similar to what is below:
+--------+------+
| Name | ID |
+--------+------+
| Jim | 1 |
| Sarah | 1 |
| Tim | 1 |
| Jim | 2 |
| Rachel | 1 |
| Sarah | 2 |
| Jim | 3 |
| Sarah | 3 |
| Rachel | 2 |
| Tim | 2 |
+--------+------+
You can do this with a simple COUNTIF() and getting a little creative with your cell references:
=COUNTIF($A$1:$A1, A2) + 1
Put that in B2 (assuming your list with headers starts in A1) and then copy down.
COUNTIF() here is counting the number of times the name in the adjacent cell has appears in all of the cells above it. As you copy it down, that range will grow to include all cells between A1 and the next row up.
In MS Excel, I want to count the number of distinct categories (ignoring a specific item) based on a different column. Also, I want to find the average and the max for the same selection. This is the data:
+--------+-----------+-------+
| Person | idea | score |
+--------+-----------+-------+
| George | vacuum | 9 |
| George | box | 6 |
| George | x | 1 |
| Joe | scoop | 4 |
| Joe | x | 1 |
| Joe | x | 1 |
| Joe | scoop | 4 |
| Joe | gear | 7 |
| Mike | harvester | 10 |
| Mike | gear | 7 |
| Mike | box | 6 |
+--------+-----------+-------+
The result should be the following:
+--------+----------------+------------+-----------+
| Person | distinct ideas | Avg. score | Max score |
+--------+----------------+------------+-----------+
| George | 2 | 5.3 | 9 |
| Joe | 2 | 3.4 | 7 |
| Mike | 3 | 7.7 | 10 |
+--------+----------------+------------+-----------+
Because Joe has two "scoop" and one "gear" idea, and I want to ignore the "x" items.
I reluctantly gave up and did it manually for each person, e.g., this is for the first person:
SUM(IF(FREQUENCY(MATCH(B2:B4,B2:B4,0),MATCH(B2:B4,B2:B4,0))>0,1))-IF(COUNTIF(B2:B4,"x")>0,1,0)
Doesn't Excel have functions to return a range instead of a value? If I could select the range based on the name of the person in the first columns, I could count distinct occurrences or find the average in another column.
Add a 4th column and label it Distinct Ideas
If your table starts in A1, then:
EDIT: Formula changed to exclude "x". Screen shot also changed
D2: =IF(TRIM($B2)="x",0,IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1))
and fill down.
Then construct a Pivot table
Person to Row Labels
Distinct Ideas to Values area
score to Values and select to Average
Score to Values area and Select Max
Format as desired. Here is one result: