I need to count the number of cells in which the cells in "LIST A" appear in the set of values contained in column D AND the cells in "LIST B" do not appear in column E.
I am trying to use something like the following array formula, but so far have had limited success:
={SUM(COUNTIFS(A2:A21,D2:D5,B2:B21,"<>"&E2:E3))}
Please note that the data contained in this example is different to the data in my real table. The real table is considerably longer and more complex than this table.
Any suggestions?
just for your example the formula like in my comment will be enough
=SUMPRODUCT(COUNTIF(D2:D5,A2:A21)*NOT(COUNTIF(E2:E5,B2:B21)))
the problem ocures if you have multiple values you want to exclude. then you need to use a negative countif(s)
=SUMPRODUCT(1*NOT(COUNTIF(E2:E5,B2:B21)))
this would count all lines which contain anything of the exclude list. But the NOT inside the sumproduct will switch it to opposite (the 1* is needed cus it would only contain bool which can't be count)
if you have column C with bool (true/false or 1/0) you can simply add that:
=SUMPRODUCT(COUNTIF(D2:D5,A2:A21)*NOT(COUNTIF(E2:E5,B2:B21))*C2:C21)
or also (C2:C21>12) if that is what you need... but you also could include it to the include list (if A is A/B/E/F and C is (2/4/6)
=SUMPRODUCT(COUNTIFS(D2:D5,A2:A21,F2:F5,C2:C21)*NOT(COUNTIF(E2:E5,B2:B21)))
But every exclude needs its own countif (B is not X/Y and C is not 8/9/11)
=SUMPRODUCT(COUNTIFS(D2:D5,A2:A21)*NOT(COUNTIF(E2:E5,B2:B21))*NOT(COUNTIF(F2:F5,C2:C21))
As already said: Having formulas which return "" may return false counts (keep that in mind)
Best to switch to SUMPRODUCT in such cases:
=SUMPRODUCT(0+ISNUMBER(MATCH(A2:A21,D2:D5,0)),1-ISNUMBER(MATCH(B2:B21,E2:E5,0)))
Regards
Related
The blue columns is the data given and the red columns is what is being calculated. Then the table to the right is what I am referencing. So, F2 will be calculated by the following steps:
Look at the Machinery column (D), if the cell contains LF, select column K, otherwise select column L
Look at the Grade column (E), if the cell contains RG, select rows 4:8, otherwise select rows 9:12.
Look at the Species column (A), if the cell contains MS, select rows 5 and 10, otherwise.......
Where every the most selected cell is in columns K and L, copy into column F.
Multiply column F by column C.
I don't want to make another column for my final result. I did in the picture to show the two steps separately. So column F should be the final answer (F2 = 107.33). The reference table can be formatted differently as well.
At first, I tried using nested-if statements, but realized that I would have like 20+ if statements for all the different outcomes. I think I would want to use the SEARCH function to find weather of not the cell contains a specific piece of information. Then I would probably use some sort of combination of match, if, v-lookup, index, search, but I am not sure how to condense these.
Any suggestion?
SUMPRODUCT is the function you need. I quickly created some test data on the lines of what you shared like this:
Then I entered the below formula in cell F2
=SUMPRODUCT(($I$4:$I$9=E2)*($J$4:$J$9=LEFT(A2,FIND(" ",A2)-1))*IF(ISERROR(FIND("LF",D2,1)),$L$4:$L$9,$K$4:$K$9))
The formula may look a little scary but is indeed very simple as each sub formula checks for a condition that you would want to evaluate. So, for example,
($I$4:$I$9=E2)
is looking for rows that match GRADE of the current row in range $I$4:$I$9 and so on. The * ensures that the arrays thus returned are multiplied and only the value where all conditions are true remains.
Since some of your conditions require looking for partial content like in Species and Machine, I have used Left and Find functions within Sumproduct
This formula simply returns the value from either column K or L based on the matching conditions and you may easily extend it or add more conditions.
I can't get my head wrapped around this multi conditional between two columns. I have two columns A and B but would like to use some formulas to compare each "grouping" of column A. For example in Column A, if all "group 2" has all Column B values as Pass, it is a pass.
Edit: I've updated it with some more rules since this just a bit more complicated for me to wrap my head around.
There are only 5 criteria:
PASS, PROG, UNAVAIL, IGNORE, "BLANK"
Rules:
FAIL if subgroup has 1 or more fail
IGNORE if subgroup has 1 or more ignore
PASS if ALL PASS or combination of PASS and UNAVAIL
PROG if NOT fail and a combination of PASS, UNAVAIL, PROG
"BLANK"s are treated as UNAVAIL
Appreciate any help, thank you!
(Answer changed to reflect new criteria)
This sheet:
Was created with the following two formulas (using named ranges in A-C where the name is in the first row):
In C1 I entered (then copied)
=CONCATENATE(TRIM(A2),"-", IF(LEN(TRIM(B2)) > 0, TRIM(B2), "UNAVAIL"))
In F2 I entered (then copied)
=IF(COUNTIF(Tag, E2 &"-FAIL") >0, "FAIL",IF(COUNTIF(Tag, E2 &"-IGNORE") >0,"IGNORE",IF(COUNTIF(Group,E2) = COUNTIF(Tag, E2 &"-PASS") + COUNTIF(Tag, E2 &"-UNAVAIL"),"PASS","PROG")))
The 4th case is like an else at the bottom of a switch -- no need to explicitly check the condition.
along the same lines,
add a column C, where if the result is pass value is 0,
result is fail value will be -100000 or so (large negative)
for uncertain use some prime negative like -3/
then use a pivot table and use the sum of the values
Then you can use formulas to deduce different conditions.
the use of large negative number is to be be able to if all the results
are uncertain, as long as they don't overlap the range less than -100000 or so.
anyway you get the idea.
This formula may work (enter as an array formula CTRL-ENTER):
=IF(SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="FAIL",1,0))>0,"FAIL",IF(SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="IGNORE",1,0))>0,"IGNORE",IF(SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="PASS",1,0))+SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="UNAVAIL",1,0))+SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")=0,1,0))=SUM(IF($A$2:$A$23=$E2,1,0)),"PASS","PROG")))
Here Group and Result are in $A$2:$A$23 and $B$2:$B$23, respectively. E2:E11 holds "s1" through "s10". I assumed Rule 3 meant that a combination of UNAVAIL and blanks is a PASS --- the logic could be modified to make that a PROG.
I am currently drawing up a spreadsheet that will automatically remove duplicates and alphabetize a list:
I am using the COUNTIF() function in column G to create a sort order and then VLOOKUP() to find the sort in column J.
The problem I am having is that I can't seem to get my SortOrder column to function properly. At the moment it creates an index for two number 1's meaning the cell highlighted in yellow is missed out and the last entry in the sorted list is null:
If anyone can find and rectify this mistake for me I'll be very grateful as it has been driving me insane all day! Many thanks.
I'll provide my usual method for doing an automatic pulling-in of raw data into a sorted, duplicate-removed list:
Assume raw data is in column A. In column B, use this formula to increase the counter each time the row shows a non-duplicate item in column A. Hardcord B2 to be "1", and use this formula in B3 and drag down.
=if(iserror(match(A3,$A$2:A2,0)),B2+1,B2)
This takes advantage of the fact that when we refer to this row counter in our revised list, we will use the match function, which only checks for the first matching number. Then say you want your new list of data on column D (usually I do this for display purposes, so either 'group-out' [hide] columns that form the formulas, or do this on another tab). You can avoid this step, but if you are already using helper columns I usually do each step in a different column - easier to document. In column C, starting in C3 [C2 hardcoded to 1] and drag down, just have a simple counter, which error-checks to the stop at the end of your list:
=if(C2<max(B:B),C2+1," ")
Then in column D, starting at D2 and dragged down:
=iferror(index(A:A,match(C2,B:B,0)),"")
The index function is like half of the vlookup function - it pulls the result out of a given array, when you provide it with a row number. The match function is like the other half of the vlookup function - it provides you with the row number where an item appears in a given array.
Hope this helps you in the future as well.
The actual reason that this is going wrong as implied by Jeeped's comment is that you can't meaningfully compare a string to a number unless you do a conversion because they are stored differently. So COUNTIF counts numbers and text separately.
20212 will give a count of 1 because it is the only (or lowest) number.
CS10Z002 will give a count of 1 because it is the first text string in alphabetical order.
Another approach is to add the count of numbers to the count if the current cell contains text:-
=COUNTIF(INDIRECT("$D$2:$D$"&$F$3),"<="&D2)+ISTEXT(D2)*COUNT(INDIRECT("$D$2:$D$"&$F$3))
It's easier to show the result of three different conversions with some test data:-
(0) No conversion - just use COUNTIF
=COUNTIF(D$2:D$7,"<="&D2)
"999"<"abc"<"def", 999<1000
(1) Count everything as text
=SUMPRODUCT(--(D$2:D$7&""<=D2&""))
"1000"<"999"
(2) Count numbers before text
=COUNTIF(D$2:D$7,"<="&D2)+ISTEXT(D2)*COUNT(D$2:D$7)
999<1000<"999"
(3) Count everything as text but convert numbers with leading zeroes
=SUMPRODUCT(--(TEXT(D$2:D$7,"000000")<=TEXT(D2,"000000")))
"000999" = "000999", "000999"<"001000"
is there a way to combine a search formula with a lookup or possibly use an if then statement. I think I have the first part working but need help with the second part. I am looking for values in column A and based on the values found in column A, I need to look at values in other columns and return the value found in that column.
Example, if column A contains value "car", I need to look at column B and return the value found in column B in column F , if column A contain value "boat", I need to look at column C and return the value found in column C in column F.
Any help would be much appreciated
Assuming that you have a list of possible values: car, boat, bike, plane, ... that would lead you to look for values in column B, C, D, E, ... I suggest you do the following:
Define the name "transportation" (whatever name you want to call it) with the types of transportation you need - for example, ={"car", "bike", "tram", "bus", "boat"} . On Office for Mac 2011 you do this with Insert->Name->Define... - for other versions of Excel it might be different (but note - you actually type both the = sign and the {} curly braces around the list of values you want to be able to look up). Put them in the order of the columns that you want.
For every lookup that you need, you can now write
=INDEX(B4:F4,0,MATCH(A4,transportation,0))
if the value (car, bus etc) is in cell A4, and you want to look up the corresponding value from columns B through F.
If you have column headings above your columns, you can use the MATCH function without having to define a name explicitly. For example, if you have car, bike, tram etc in cells B1:F1, you can use
=INDEX(B4:F4, 0, MATCH(A4, $B$1:$F$1, 0))
to do the lookup.
Explanation: the MATCH function (with third parameter 0) looks for the exact match for the first value (in cell A4 in this case) in the array that is the second parameter (either the named range, or the range with fixed address that I gave above). You then look up the appropriate cell using the INDEX function which gives you an offset into the range (B4:B4 in the above) of cells where you need to do the lookup.
I trust you can adapt this to your exact needs. Ask if you need more help.
The following formula is the simplest way I can think to do it:
In cell F1, the formula would be
=IF(A1="car",B1,C1)
This is case insensitive, so it should work for CAR as well. But bear in mind that this has the downside that with a formula this simple, ANY value in A1 other than "car" (not just "boat") would lead to the other value ending up in the F column.
=IF(A1="car",B1,IF(A1="boat",C1,""))
My data table is like the image above. I can easily count the number of Male participants in group B or C using this array formula:
=SUM(COUNTIFS($B:$B, $E3, $C:$C, $F3:$F4))
The result is 3 as expected. However I'm gonna do the reverse thing, that is count the number of Male participants in NOT group B or C. The result should be 1 but currently I'm stuck at this.
Can anybody show me a way please (preferably not just counting the number of all Male participants and then do a subtraction)? I have even tried to change the values in the Group to something like <>B and <>C but it just doesn't work.
As you only have 2 in the group you can easily use COUNTIFS with 2 separate criteria, i.e.
=COUNTIFS($B:$B,$E3,$C:$C,"<>"&$F3,$C:$C,"<>"&$F4)
but clearly that might not be desirable for a large group, so you could use SUMPRODUCT like this to reference the group once
=SUMPRODUCT(($B:$B=$E3)*ISNA(MATCH($C:$C,$F3:$F4,0)))
ISNA will exclude matching rows - to include use ISNUMBER
You can replace F3:F4 with any single row or column of values
Note: whole columns with SUMPRODUCT will work (post Excel 2003) but is undesirable as Jerry says
Hmm, the thing with the formula right now is that the first COUNTIFS (for F3) will return 2 and the second COUNTIFS (for F4) will return 3, which SUM converts into 5 when you try:
=SUM(COUNTIFS($B:$B, $E3, $C:$C, "<>"&$F3:$F4))
I would suggest using SUMPRODUCT instead:
=SUMPRODUCT(($B:$B=$E3)*($C:$C<>$F3)*($C:$C<>$F4))
And maybe make the range smaller since this can take some time (you don't need to insert this as an array formula).
Otherwise, another option would be to count all the Males, and then subtract the counts for group B and subsequently C:
=COUNTIF($B:$B, $E3)-SUM(COUNTIFS($B:$B, $E3, $C:$C, $F3:$F4))