Count number of rows where value in a column is not a part of a list - excel

I have a data set, let's say like this:
Item Name
Apple
Carrot
Carrot
Pear
Pear
Pineapple
Radish
Orange
Orange
Pineapple
Pineapple
and I also have a LIST like this:
List of Items:
Apple
Orange
Pineapple
How to write a formula that will count how many rows in the dataset have a value that is NOT a part of the list? ... so in this case 5...

You could just take the number which are in the list away from the total:-
=COUNTA($A$2:$A$20)-SUMPRODUCT(COUNTIF($A$2:$A$20,$B$2:$B$20))
assuming data items in column A and list in column B.

You need to create a named range of the list.
Mark your list of items and in the "name box" write LIST.
Now if the long list is in column A, then in column B write the following formula:
=IFERROR(VLOOKUP(A1;LIST;1;FALSE);1)
It will find the match in the LIST if it excists, if not write "1".

=COUNTIFS(rng,"<>Apple",rng,"<>Orange",rng,"<>Pineapple")
Assuming your named range for the long column is rng.
Obviously this works best if your short list is very short.

Related

Excel: Grouping and restructuring data in Excel

In Excel, I want to convert the table on the top (Initial data) into the one at the bottom (Desired output).
I want to group the items in the second row by the first row, and then generate one column per unique value of the first row and list the items of the corresponding group in that column.
Is there a way to do that without manually copying cells?
Table: Initial data
Fruit
Banana
Fruit
Apple
Fruit
Grape
Vegetable
Spinach
Vegetable
Eggplant
Table: Desired output
Fruit
Vegetable
Banane
Spinach
Apple
Eggplant
Grape
If you have access to the UNIQUE and FILTER functions (Excel 365), you could accomplish this as follows.
Assuming your data is in A1:B5. In D1 enter:
=TRANSPOSE(UNIQUE($A$1:$A$5))
This will get you the unique values from the cells in A in D1:E1. Then in D2 enter:
=FILTER($B$1:$B$5,$A$1:$A$5=D1)
And drag to the right.
I.e. you do this:
Result:

Does excel have an if statement equivelent? I can't get this program to work

The program has 5 columns.
Column A has item names
Column B has item sizes
Column C has item quantities
Column D has items that i need
Column E has the sizes for those items in the rows corresponding to the items
Most items do not have multiple sizes, but for the ones that do, there will be multiple entries of that item in column A.
What I need to do is take all the items from column D and find them in column A and give me the corresponding quantity from C.
I have been using this code to achieve this. =INDEX(C:C,MATCH(D:D,A:A,0))
This works for all items besides the ones with multiple sizes. For these items it just spits back the first size number every time.
Would there be a way to match A and D, and then check if there is a value in the size column, if so, give out the correct number?
I see how my wording is confusing here is an example of what I mean.
apples 5lb bag 12 apples 10lb bag
apples 10lb bag 13
bananas 5 grapes
grapes 7
Which using the is line of code "=INDEX(C:C,MATCH(D:D,A:A,0)) " would result in giving me the correct "7" for the grapes, but for the apples, it would give me the first result it comes across, which is the 12.
How would I get it to check the other columns to give me the 13 for apples?
If I understand correctly then this will get you the correct number:
=IF(E2<>"",SUMIFS(C:C,A:A,D2,B:B,E2),SUMIFS(C:C,A:A,D2))

Delete row if column contains value from to-remove-list with wildcard

How do I make a wildcard so that I can find something that's not an exact match? I've tried taking out the 1, and also adding &"*" after A1 (the lookup value).
In other words, if I had app in the blacklist, how do I make it match apple so that it returns "Delete"?
Given sheet 2:
ColumnA
-------
apple
orange
You can flag the rows in sheet 1 where a value exists in sheet 2:
ColumnA ColumnB
------- --------------
pear =IF(ISERROR(VLOOKUP(A1,Sheet2!A:A,1,FALSE)),"Keep","Delete")
apple =IF(ISERROR(VLOOKUP(A2,Sheet2!A:A,1,FALSE)),"Keep","Delete")
cherry =IF(ISERROR(VLOOKUP(A3,Sheet2!A:A,1,FALSE)),"Keep","Delete")
orange =IF(ISERROR(VLOOKUP(A4,Sheet2!A:A,1,FALSE)),"Keep","Delete")
plum =IF(ISERROR(VLOOKUP(A5,Sheet2!A:A,1,FALSE)),"Keep","Delete")
The resulting data looks like this:
ColumnA ColumnB
------- --------------
pear Keep
apple Delete
cherry Keep
orange Delete
plum Keep
Use SEARCH Function but you will need to enter it as Array Formula.
Something like:
=IF(SUM(IFERROR(SEARCH(Sheet2!A$1:A$2,Sheet1!A1),0))>0,"Delete","Keep")
Enter using Ctrl+Shift+Enter.
This will check app or apple and all that's listed on Sheet2.
SEARCH Function also accepts wildcards (eg. ?- for single character, * - for 0 or more)
Important: I didn't use the overkill search range Sheet2!A:A since it will eat up significant calculation time.
To expand on L42's answer:
If the number of entries in Sheet1!A and Sheet2!A are unknown, the following formula will work with a maximum number of entries in Sheet2!A limited to 256.
=IF(A1<>"",IF(SUM(IFERROR(SEARCH(Sheet2!A$1:A$256,Sheet1!A1),0))+COUNTA(Sheet2!A$1:A$256)-256>0,"Delete","Keep"),"")
Change the value 256 in all three instances above to suit your needs.

miss and match on excel

I'm not even sure if what i want to happen is possible but here it is :
So i have a list on column A and another on column B. Say, column A has apples, bananas, eggs... Then column B has apple pies, banana pies, egg pies...on column C, I want excel to tell me that apples and apple pies match and bananas and banana pies match, and so on. Then tell me if they don't match at all. I want it so that even if i want 2 values from column A to match with a value in column B. For example aside from apples there could also be pears in column A but i would still want pears to return a match value with apple pies. I hope this is not too confusing
... Thanks in advance!
Ok, I am going to give you multiple answers because I am not sure what the question is. If Gary's Student's comment is the right answer and you just want to match the contents then all you need to do is put this in C2 and copy it to every row:
=IF(ISERROR(FIND(A2,B2)),"no match","match")
But if your comment about 1-2=bad, 3-8=good and 9-10=very good is what you really want then all you need to do is put this in C2 and copy it to every row:
=IF(B2=CHOOSE(A2,"bad","bad","good","good","good","good","good","good","very good","very good"),"match","no match")
What that does is change the number in column A to be the equivalent string and then match that string against column B.
But if you are looking for a solution that works for both things then you need a dictionary. If you use ALL the piossible values from B as the keys and each matching value from A as the values then you can call MATCH twice and see if the value belongs to the key.
So for example the dictionary for the pie example might look like this (notice that pies can have more than one ingredient):
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 lemon pie lemon egg
3 apple pie apple pear
4 pear pie pear
5 egg pie egg
And the dictionary for the bad and good example would look like:
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 bad 1 2
3 good 3 4 5 6 7 8
4 very good 9 10
Then you can stick this in C2 and copy it to every row:
=IF(ISNA(MATCH(A2,OFFSET(F$1:O$1,MATCH(B2,E$2:E$20,0),0),0)),"no match","match")
What this does is look up the value in column B in the dictionary and find what row it is in. Then it offsets F$1:O$1 by that many rows so that the range for the outside match is the correct list of incgredients. Then it matches the value in column A by the list of ingredients that the offseted inside match produced.
Maybe some screenshots will help:

Multiple vlookups in one cell

Ok I have two vlookups that both search from the same array but with different criterias.The first vlookup would search for the Price category. The second vlookup would seek the type of product.
This is an example array:
ID Price Type
1 Banana Fruit
2 Apple Fruit
3 Orange Fruit
4 Corn Flakes Cereal
5 Monster Energy Drink
The syntax would be:
Search for the first vlookup, if there is no results, try to search for the second vlookup.
If the first or second vlookup is true, then return value ID.
I have already made the vlookups but I have no idea how to combine both in one cell
Edit: Vlookups
=Vlookup(A2,E4:G8,2,0)
=Vlookup(B2,E4:G8,2,0)
And the lists:
A column B column
List 1 List 2
Banana Hardware
Carrot Vegetable
Orange Chocolate
Mango Candy
Fruit
It may be as simple as this:
=IFERROR(Vlookup(A2,E4:G8,2,0),Vlookup(B2,E4:G8,2,0))
Try to find one, if it fails try the other.
This formula returns corressponding ID if found value from A2 or B2 in ranges F4:F8 or G4:G8 respectively, or "not found in both columns" if both values not found:
=IFERROR(INDEX(E4:E8,IFERROR(MATCH(A2,F4:F8,0),MATCH(B2,G4:G8,0))),"not found in both columns")

Resources