COUNTIF range does not equal range - excel

The data I'm looking to get is something like this:
+----------+-------+
| Location | Count |
+----------+-------+
| Jungle | 2 |
| Ocean | 4 |
| Other | 2 |
+----------+-------+
The formula for count should look in the data range and if a cell's data does not equal any of the cell data in the rest of the location column (Jungle, Ocean) it should add that to the count. It should exclude blanks.
This is the formula I tried:
=COUNTIF(A1:H6,"<>"&E11:E12)
Here is my example sheet: https://docs.google.com/spreadsheets/d/1YbqEwa3olEXMcmU-UORfe7jwyK_-AXDomp1t5iTVUaU/edit?usp=sharing
Where am I going wrong? There are 7 other instances of colours not Green or Blue therefore I would expect this result to be output. I haven't put anything in about ignoring spaces so I would expect the result to count blanks too, but I get 0.

Don't use & - this would join E11 and E12 together so you would be looking for greenblue. You would need a COUNTIFS to get the three conditions
=COUNTIFS(A1:H6,"<>"&E11,A1:H6,"<>"&E12,A1:H6,"<>")
Here is a more general way of doing it
=COUNTA(A1:H6)-SUMPRODUCT(COUNTIF(A1:H6,E11:E12))
See this useful reference

The COUNTIFS formula is your friend here. This formula should work for that cell:
=COUNTIFS(A1:H6,"<>"&E11,A1:H6,"<>"&E12,A1:H6,"<>")

The problem with a 'does not equal OR does not equal' is that when it is not equal to one, it could be equal to the other and vice-versa. Additionally, you range to count from is 2 dimensional so you cannot use rows of criteria. Use SUMPRODUCT and individual criteria multiplied against each other.
=SUMPRODUCT((A1:H6<>"")*(A1:H6<>E11)*(A1:H6<>E12))
Any of those three conditions that is not true is considered zero. Anything multiplied by zero is zero. 1 x 1 x 1 is 1.
For large numbers of exclusions, you will want to use an array formula (with CSE) to count them and then subtract that total from a COUNTA total of the entire range.
=COUNTA(A1:H6)-SUM(COUNTIF(A1:H6,E11:E15))

Related

Excel printing a specific number in a row subject to other columns

I have an excel file with 3 columns and 100 thousand rows. My goal is to print the number of column A, where the number in column C is the maximum and the number in column B is higher or equal to 0.9. Like this example:
-----+------+-----
A | B | C
-----+------+-----
1 | 0.9 | 130
2 | 0 | 200
3 | 0.95 | 90
In this example for example it should print '1' since column 1 and 3 are higher than 0.9 but 1 is higher than 3 in column C. Anyway to do this in excel?
Assuming your data in column C is positive (or at least, that the maximum value is positive), you can use this array formula:
= INDEX(A:A,MATCH(LARGE(((B:B>=0.9)+0)*(C:C),1),((B:B>=0.9)+0)*(C:C),0))
Note this is an array formula, so you must press Ctrl+Shift+Enter after typing in the formula.
This gets pretty ugly since there is no =MAXIFS() formula. Instead, an array formula will do the trick:
=SUMIFS(A1:A3, C1:C3,MAX(IF(B1:B3>=0.9, C1:C3, 0)), B1:B3,">=.9")
Hit Ctrl+Shift+Enter when entering that so Excel will interpret as an array formula.
The Sumifs() here isn't summing more than one value so no worries there. We are grabbing the value from A1:A3 where C1:C3 is equal to the MAX() of that column where B1:B3 is greater than or equal to .9. Which solves that max() issue. And then we are then only allowing selection A1:A3 where B1:B3 is greater than or equal to .9.
It's not pretty, and it requires us to check that >=.9 condition twice, but it does the job.
Try using this array formula =SUMPRODUCT(INDEX(A2:A20,MATCH(MAX(--($B$2:$B$20>=0.9)*C2:C20),--($B$2:$B$20>=0.9)*C2:C20,0),1)) in cell D2. Confirm it with CTRL+SHIFT+ENTER.
This is the array formula (means you have to click Ctrl + Shift + Enter altogether) what I came up with:
=INDEX(A:C,MATCH(MAX(--(B:B>=0.9)*(C:C)),(B:B>=0.9)*(C:C),0),1)
Please note that I used the whole column but I will suggest to only use the ranges that are needed for faster speed.

Excel formula to sum values based on reference number in another column

I have two columns. One is an amount and the other is a reference number. I need a formula to sum all amounts per reference number next to the reference number in order to sort from highest to lowest value per reference.
Amount | Reference | Sum per Reference
122.00 | 405221 | 316
194.00 | 405221 | 316
339.80 | 405682 | 851.25
296.45 | 405682 | 851.25
215.00 | 405682 | 851.25
The closest formula I found on this website, was:
=IF((AR2=AR3),"",SUM($AQ2:AQ2-SUM(AV$1:AV1)))
This however only puts the sum value (like a subtotal) at the last reference number and leaves the other ones blank. I need it to put the sum value for each reference number next to all the lines and have not blank spaces?
It sounds like what you're looking for is the SUMIF function. It sums values by a criterion, so in this case we can use it to sum all values that match another value. Assuming your values are in Column A and your criteria are in Column B:
=SUMIF($B:$B,$B2,$A:$A) Put this formula in your "SUM per Reference" column and copy it down, and you should get a good result.

Excel - SUM Columns IF column header is EQUAL to while another column header is EQUAL to BUT value is not 0

I have a table like this:
January February March Year to Date
Actual | Target Actual | Target Actual | Target Actual | Target
100 | 100 50 | 100 0 | 100 150 | 200
What I basically want to achieve is for Year to Date to SUM Target if Actual of each month is greater than zero (0).
Can this be achieved via Excel Formulas?
=SUMPRODUCT(B3:G3,((A3:F3)>0)*1,(B2:G2="Target")*1)
I am assuming that you can use column to the left of your data. If you can't just skip January in the sumproduct and add it with a simple IF.
Aaa +1 to this would be easier if you could re-arrange data.
The SUMIF function is helpful here.
Are you able to use an additional row? If not, is your Target always 100?
Assuming yes to one of these, the below will work. Highlighted cells have highlighted equations.
To calculate YTD Target: Green uses extra row 4, orange assumes target is always the same (100)
NB: the empty column A is so that the same equation canbe used in all cells on row 4. You can get rid of it and the equation in B4 without anything messing up.

Excel, sum range split

I have a google spreadsheet and I want calculate to some data...
I want to sum the splits in a range
1 | A1 |
2 | 1Q1 |
3 | 3Q2 |
4 | 5Q7 |
I need the sum of the integers after the letter "Q" so in the example above I would get 1+2+7=10
This formula will do it all in one, just set the range in the formula , ie A2:A4
=SUM(VALUE((RIGHT(A2:A4,LEN(A2:A4)-FIND("Q",A2:A4,1)))))
Press CTRL+SHIFT+ENTER to enter the array formula.
You can use the function VALUE(RIGHT(text)) which will give you back the number value of the rightmost character in the string. Then use those values in your sum.
Assuming that the 3rd character is the number, you could try something like
=VALUE(MID(A:A,3,len(A:A)))
in column B
then sum that like this (for the 1st 3 rows):
=SUM(B1:B3)

Excel Function Help - Compare 2 Cells in Worksheet to 2 Cells in another worksheet, if they match, return value from a different column

I'm wondering if someone would be able to offer some advice on the best way to do this please:
Data in Worksheet # 1
Col A | Col B | Col C
Part-1 | 8 | 2
Part-2 | 7 | 7
Part-7 | 9 | 4
Part-8 | 2 | 6
Data in Worksheet # 2
Col A | Col B | Col C
Part-1 | 8 | *Return value* (If Part-1 is found and 8 matches, return 2)
Part-2 | 7 | *Return value*
Part-3 | 8 | *Return value*
In Worksheet#2 in Cell C2 - I would like to check if the Part-1 in A1 is found in Col A in Worksheet#1. If it is, then I would also like to make sure the Number is B2 in Worksheet#2 matches the Qty in Col B next to the same part#, if both the Part# and Qty match, then i would like to copy across the value from the corresponding cell in Col C in Worksheet#1, to Col C in Worksheet#2. If it does not match, I would like it to return a 0.
Here is the a variation on Reinier's second approach in a form that will work in any version of Excel. You can use references to the specific data ranges, as I have done here, or to entire columns.
=SUM((A2=Sheet1!$A$2:$A$5)*(Sheet2!B2=Sheet1!$B$2:$B$5)*Sheet1!$C$2:$C$5)
This is an array formula, so it needs to be entered with the Control-Shift-Enter combination. It performs the same operation as the SUMPRODUCT. (There are several other ways to do this, such as using MATCH with INDEX or OFFSET.)
Essentially, what you are doing is a lookup based on values in two columns. Looking at it from that angle, you can use a the SUMPRODUCT function, which is supported in any version of Excel. Enter the following in Sheet2, cell C2:
=SUMPRODUCT((Sheet1!$A:$A=$A2)*(Sheet1!$B:$B=$B2)*Sheet1!$C:$C)
Select and drag down the right-bottom corner of C2 to complete column C.
This only works by virtue of the fact that the values in Sheet1, column C, are numbers. It breaks if value pairs in column A and B of Sheet1 occur multiple times, but you did not address that situation in your question in the first place.
For versions 2007 and up, you can use the more convenient function SUMIFS with basically the same approach:
=SUMIFS(Sheet1!$C:$C,Sheet1!$A:$A,$A1,Sheet1!$B:$B,$B1)
Alternatively, you can use a combination of IF and VLOOKUP functions. A formula that will work for Excel 2007 or newer is the following:
=IFERROR(IF(VLOOKUP($A1,Sheet1!$A:$C,2,FALSE)=$B1,VLOOKUP($A1,Sheet1!$A:$C,3,FALSE),0),0)
Older versions of Excel do not support IFERROR, but you can still use a similar approach as explained here.
I have uploaded an example workbook here, which includes an alternative method in column D of Sheet2 as well.

Resources