How to remove rows in Excel where inclusions are not met? - excel

For example, say I have two columns:
ID, Code
1 A
1 B
1 G
2 A
2 F
3 A
3 B
3 C
3 F
4 B
I want to delete any rows for which the ID number is not associated with both A and B somewhere.
So for example all the rows with ID=1 are OK to keep because it is associated with code A and code B.
All rows with ID=2 are to be deleted because it has A, but no B.
All rows with ID=3 are OK because it has both A and B.
All rows with ID=4 are to be deleted because it only has B, no A.
The real file has many rows so I can't do this by hand. Is there a quicker way? I tried using Vlookups somehow but I can't find a way to easily tell which ones to delete.

Using COUNTIFS:
=COUNTIFS(A:A,A1,B:B,"A")+COUNTIFS(A:A,A1,B:B,"B")
Delete all the results that returns 0 or 1 (and keep all the results that give 2).

using 2 temporary helper columns in C & D
1st column = A2 & B2, copied down
2nd column =IF( OR( ISERROR(Vlookup(A2 & "A",C:C,1,FALSE)),ISERROR(Vlookup(A2 & "A",C:C,1,FALSE))),"DeleteMe","SaveMe")
Follow Instructions in column D
Delete Columns C & D
Don't forget to try this on a backup first, so you can enure it works to your satisfaction

Related

Using excel to count with conditions

I have an excel sheet that looks like this (with many more columns and rows of course):
condition a
condition b
condition c
condition d
result (a,b)
result (c,d)
yes
no
yes
no
0
1
no
no
no
yes
0
1
yes
yes
no
no
1
0
...
Now, I only want to separately count the occurrences of either a or b or both are occurring per row, but want to exclude all instances where either a or b (or both) are occurring together with c or d, since I want to count the occurrences where either c or d or both are apperearing separetely. I have toyed around with the idea of using the countifs, but my problem is that I want to count every row separately, so if a and b occur together I only want to count them once, so if I applied countifs to all the colums together, it would count all instances of yes in the a and b column.
For example here in the first row, I would get a 1 for c,d and a 0 for a,b since while there is a yes for a in the first row, there is also one for c.
In the second row, we only have yes for d so it's easy that it's easyily 1 for c,d and 0 for a,b.
And finally in the third row we only have a,b both yes, so it's 1 for a,b since I want to know the occurence per row, and since there is no for both c and d, and so it's 0 for c,d since both are no.
Does anyone know how to solve this in excel? Thank you all for your help
Use AND and OR (COLUMN E):
=--AND(AND(C2<>"yes",D2<>"yes"),OR(A2="yes",B2="yes"))
And (COLUMN F)
=--OR(D2="yes",C2="yes")
If you want to count without the helper columns:
A,B:
=SUMPRODUCT(((C2:C4<>"yes")*(D2:D4<>"yes"))*((A2:A4="yes")+(B2:B4="yes")>0))
C,D:
=SUMPRODUCT(--((C2:C4="yes")+(D2:D4="Yes")>0))

How to use SUMIFS and SUMPRODUCT function **with a multiplier column** for summing values if criteria range exists in a range?

This question refers to this Stack Overflow question.
This is the original question:
A B C
a 3 d
b 1 a
c 8 e
d 5
I want to use SUMIFS function, sum range is B1:B4, if the corresponding value in column A exists in column C, sum the values in column B, in this case the sum will be 3 + 5 = 8.
The answer turned out to be:
=SUMPRODUCT(SUMIF(A1:A4,C1:C3,B1:B4))
I would like to create the same result, but with a multiplier on one of the ranges.
Here's my question:
A B C D
a 3 d 3
b 1 a 1
c 8 e 1
d 5 d 3
The only thing I would like to do differently is add a range D1:D3 that acts as a multiplier. In this case, the sum I want would be (3x3)+(5x3)= 24.
One challenge is that the ranges are different sizes in the "Test Data" google sheet linked below. The "Test Data" sheet is an example of how I would like to total daily calories based on the number of servings of items that I eat as dictated by the "multiplier column."
I would like the numbers in C2:C27 to be a multiplier and factored into the total in D36.
For example, if I ate 2 servings of Beef, then 2 servings worth of Beef's ​calories would be displayed in the daily totals below the data. Currently, using the formula =SUMPRODUCT(SUMIF(Meal_Items!$A$2:$A$100,$D$2:$D$28,Meal_Items!$B$2:$B$100)), only 1 serving of beef is weighted.
Test Data
See linked Test Data set above
The original question could also be solved with this formula
=SUMPRODUCT((COUNTIF(C1:C3,A1:A4)>0)+0,B1:B4)
using that version it's a simple matter to add one or more multiplier columns
=SUMPRODUCT((COUNTIF(C1:C3,A1:A4)>0)+0,B1:B4,D1:D4)
Given discussion in comments this formula should do what you want in either Excel or google sheets
=SUMPRODUCT(IFERROR(LOOKUP($D$2:$D$28,Meal_Items!$A$2:$A$100‌​,Meal_Items!$B$2:$B$‌​100),0),$C$2:$C$28)
If you have actually put A, B, C, etc into the header row (row 1) then this will not work until you either rename your header column labels appropriately or use data range references in place of the full column references I've provided.
=B2*INDEX(B:B, MATCH(A2, A:A, 0))+B2*INDEX(B:B, MATCH(C2, A:A, 0))
In E1 enter:
=IF(COUNTIF(C$1:C$4,A1)>0,1,0)
and copy down. Then in another cell:
=SUMPRODUCT((E1:E4)*(D1:D4)*(B1:B4))
Data is in column BWeights are in column DCriteria are in column E

Counting instances across ranges in columns

I am creating a spreadsheet for my personal use. I need to count the number of times one column's values are equal to an adjacent column's.
Is there any way to do this in Excel without having to modify the formula every time a new row is added?
If you have column A and B now, add column C:
Column A Column B Column C
1 2 =countif(B:B, A1)
2 2
3 1
Then just copy the first value in column C, select the entire column C and paste :)
You will get:
Column C
1
2
0

EXCEL match 2 columns against each other

I have two columns of data, they look something like this:
A B C D
1 2 SOME RECORD
2 6 SOME RECORD
3 10 SOME RECORD
4
5
6
7
8
9
10
So basically column A is a list of indices, where some of them appear in column C with corresponding records saved in column D. Column B is currently empty, and what I want to do is if say index 2 appears in both column A and column C (they matches), then put the record beside C2 in the cell B2. So essentially I want it to look like this:
A B C D
1 2 SOME RECORD
2 SOME RECORD 6 SOME RECORD
3 10 SOME RECORD
4
5
6 SOME RECORD
7
8
9
10 SOME RECORD
Can someone help please?!! Thanks!!!
UPDATE: I tried this and it doesn't work. The data in column D is calculated using a UDF and is refreshing every 1 second. The VLOOKUP function fails even though I can see the 2 indices are the same!! Is it because of the format of the cell or column? I.e. does vlookup compare data type as well?
Assuming your data in A starts from A1 - put in B1 the following and autofill:
=IFERROR(VLOOKUP($A1,$C:$D,2,0),"")
This includes handling of missing values.
You'll want this:
B1=VLOOKUP(A1, C:D, 2, FALSE)
This will look up the value in column A within the array spanning columns C and D. It will give you the value found in the second column (D). FALSE makes it an exact match, otherwise you might get 2 and 20 matching because hey, they're kind of similar...

Compare two Excel columns, output cells in A that do not appear in B

I am trying to compare two columns in excel, A and B. Column A contains a complete list of customer numbers. Column B contains an incomplete list of the same customer numbers. So if a customer number is in A, but not in B then output that number to column C.
I'd use the MATCH function in combination with ISNA.
If I have the following table
A B C
1 4
2 3
3 1
4 7
5 2 5
6 6
7
I put in column 'A' the full customer list, and in column B is a random ordered partial list. I then put the function in C1 (and the rest of column C):
=IF(ISNA(MATCH(A1,B:B,0)),A1, "")
Now I see the values '5' and '6' only in column C, because those are the only two numbers that don't appear in column B.
In Cel C1 =IF(ISERROR(VLOOKUP(A1,$B$1:$B$10,1,FALSE)),A1,"")
Adjust for row counts and fill down against column A.
I think you're looking for something like this:
=IF(ISERROR(MATCH(A1,B1,0)),A1,"")
Propegate that formula along your new column and it'll reprint the populated Column A when Column B is a no match.
Reference URL: http://support.microsoft.com/kb/213367
(I believe I read the original question wrong, and am going on the assumption that column A and B are already sorted where the values will line up.)

Resources