Excel: Countifs "Not equal to" - excel

I'm having trouble writing a Countifs to accomplish what I want. I run a claims report every month with tons of data organized in columns and export it to excel every month. On a separate tab I have formulas that reference the tab that this data is copied to.
The formulas are used to count and organize the claims according to certain criteria. One of the columns (G:G) is "State of Jurisdiction".
The state of jurisdiction for each claim is important because certain groups of "special states" get charged a unique rate, and the "non special states" get charged a flat rate.
I've figured out how to count the "special states" without issue. my problem is counting the "non special states". I need to be able to write a countifs that references a range, for example, 010:U10, and count everything in column G EXCEPT what's stored in range O10:U10. I need 010:U10 to be able to have blank cells for expansion. Let me know if any additional information is necessary.

This could be done with Array Formulas in a single cell, but as you seem less comfortable with Excel, then I would recommend that you use some helper columns.
So instead of just reading directly from row 10 in O->U and trying to search all of them within your COUNTIFS formula, add a new row column to your data. This new column will indicate solely whether the jurisdiction in column G is a special state. So for example, assuming that $O$10:$U$10 has a list of all special states [I'm not clear on what sheet everything is on here, so you may need to adjust]. In H2 and copied down for all of your data entries, put the following [This assumes your data starts on G2]:
=IF(ISERROR(MATCH(G2,$O$10:$U$10,0)),"Non-Special State","Special State")
This says: try to MATCH the jurisdiction name from G2, out of the list of all special states in row 10. If there's no match, that means that it's not a special state, and MATCH will return an error. ISERROR will then return TRUE, which will make the IF statement give the result "Non-Special State". If MATCH finds a result, however, it will return "Special State".
Then, in your countifs formula, add this criteria:
=COUNTIFS(SUM COLUMN, OTHER CRITERIA COLUMN, OTHER CRITERIA, H:H, "Non-Special State")

The way to do exactly what you're asking for, though I'd advice against it, would be something like
=COUNT(A2:A21)-COUNTIF(A2:A21,C1)-COUNTIF(A2:A21,C2)
So on for each cell you want to include, long and tiresome.
But as you say you can count the special, just do "total" minus "special total"

Any formula that single-handedly performs this will be using cyclic calculation (with or without Ctrl+Shift+Enter or CSE) so you are going to want to cut the range of cells in column G down to what is absolutely necessary. Full column references will result in many blank cells being calculated that do not have to be.
As a standard non-CSE formula with full column reference with G:G,
=SUM(INDEX(SIGN(LEN(G:G))*ISERROR(MATCH(G:G, O10:U10, 0)), , ))
With dynamic range references,
=SUM(INDEX(SIGN(LEN(G2:INDEX(G:G, MATCH("zzz", G:G ))))*ISERROR(MATCH(G2:INDEX(G:G, MATCH("zzz", G:G)), O10:U10, 0)), , ))
      
The formula assumes that column G contains text, not numbers.

Related

EXCEL: How can I check for a keyword in a string, compare it to a range and return the corresponding value in that range?

I need to categorize data: I have a column with the description of the element I'm interested in. I want to check that description for a keyword, then check if that keyword is contained in for example column A of a separate table. If a match is found, I need returned the value in the next column (in this example column B) of the same separate table.
The attached screenshot shows how the data is organized. The column called Column1 is the output I need.
I have actually found a solution, but it involves lots of nesting, I need to force the categories and keywords in the formula and I can't add all the conditions I need; this is the current formula:
=IFERROR(IF(SEARCH("keyword";cellWithDescription);"category";);"OTHER")
And for more categories I repeat the formula instead of "OTHER":
=IFERROR(IF(SEARCH("keyword";cellWithDescription);"category";);IFERROR(IF(SEARCH("keyword2";cellWithDescription2);"category2";);"OTHER"))
which is not ideal, especially with many categories. How can I accomplish the same task with a simpler and more efficient formula, possibly comparing the keyword to values in a table (and not inside the formula itself, as I did now)?
Thanks in advance for your help!
This works for me
=INDEX(category,MATCH(1,--ISNUMBER(SEARCH(keyword,cellWithDescription)),0),1)
enter as array formula, thus ctrl+shift+enter after copying the formula (curly brackets will appear around the formula)

Excel: Index-Match using keywords and then SUM results (no VBA)

I've got a sheet with a transaction list. It includes a description of the transaction and the transaction total cost.
I'm looking for a way, without using Visual Basic, to use comma-separated keywords entered in a cell to search for all matching transactions, and then give their total value.
For example:
B4:B6 are keywords for look up.
C4 should look up in range B10:B26 for all cells containing any of the keywords in B1 (tesco OR co-op OR waitrose), and return the total value of the corresponding values in Range C10:C26. In this case it should SUM C11, C16, C21, C23, C25.
It's important to note that it shouldn't be case sensitive.
Can it be done?
You can do this with Array Functions. These functions operate similarly to "Sumifs" / "Countifs" / "Sumproduct": they perform functions normally designed to look at a specific cell, over an entire range of cells.
First let's deal with summing the total for "giffgaff" / "paypal":
In cell C5, use the following formula [As it is an Array formula, you must confirm by pressing CTRL + SHIFT + ENTER every time you edit the cell, instead of just ENTER] , and drag down to C6.
=sum(if(iserror(search(B5,$B$10:$B$26)),"",$C$10:$C26))
This looks at each row from B10:B26 (note that the entire column cannot be selected as an array formula calculates for all cells, even blank ones - so this drastically slows performance. You must specifically identify the rows you care about like this), and if there is an error when trying to search for the term in B4, that means the term does not appear on that particular row. If there is no error, it pulls the amount from column C. All of these rows are then summed together to get a single total.
Now to do the same for cell C4, you need to add in the complexity of first pulling apart each term which appears between a comma. I agree that #Tom Sharpe that you should probably do this in different cells to make it more clear what you're doing. This could be done by individually pulling terms between commas, and then having individual totals (which use the array formula above).
To do this most efficiently, I'd have use a helper column in column C, which will identify how many commas are in the text in column B, like so, in C4:
=len(B4)-len(substitute(B4,",",""))
This takes the length of B4, less the length of B4 where all commas have been replaced by blanks - giving the # of commas.
That formula can then be used to split out the words between commas, using the MID and SUBSTITUTE functions. Let me know if you need elaboration on how to do that. Once you have broken out the individual words, you can search with the Array function as above.

One to many relationship to fetch values in an alternate rows

I am trying to fetch dates from sheet1 with common ID (there are multiple occurrences in sheet1) using an array formula in a cell (then dragging it to the right side to have all the dates belong to specific ID):
=IF(COLUMNS($E2:E2)<=$D2,INDEX(Sheet1!$B$2:$B$13,SMALL(IF(Sheet1!$A$2:$A$13=Sheet2!$A2,
ROW(Sheet1!$A$2:$A$13)-ROW(Sheet1!$A$2)+1),COLUMNS($E2:E2))),"")
But, whenever I try to insert one column (for counting purposes) in b/w the columns, this formula doesn't work. I can't figure out the issue, would really appreciate the help?
Thank you.
Assuming that your first formula is in E2, and that the cells in row 2 of any newly-inserted columns will always be blank, replace the two instances of:
COLUMNS($E2:E2)
in your formula in E2 with:
COUNT(1/LEN($D2:D2))
As a way of explanation, take the formula in F2, for which this part will be:
COUNT(1/LEN($D2:E2))
(The only part having changed naturally being the end range reference.)
And let's assume that 3 new columns are inserted to the left of column E, which means that E2, F2 and G2 will now be blank, H2 will contain the entry which was previously in E2, and, for the formula in I2, the above part will now be:
COUNT(1/LEN($D2:H2))
Clearly we wish this part to continue to give 2, since this cell should still represent the second of our returns.
Using LEN is a rigorous way to determine whether a cell is empty or not. Other functions are also available for this purpose, though may give incorrect results depending upon whether the blanks in that range are "genuine" blanks or the null string "" as a result of formulas in those cells.
If a cell is empty, it has a length of 0. Hence, in this example, the above resolves to:
COUNT(1/{1,0,0,0,2})
(Where I've made some random assumptions about the lengths of the strings in cells D2 and H2.)
There are many ways to determine how many non-zeroes there are in an array. SUMPRODUCT would be one; I chose another, the logic being that the above becomes, after reciprocation with unity:
COUNT({1,#DIV/0!,#DIV/0!,#DIV/0!,0.5})
and, since COUNT ignores any errors in the range passed to it, the above resolves to 2, as desired.
Regards

How to Use Cell Text From Cell Being Checked by COUNTIF in Excel

What I'm wanting to do is have a formula in one cell that counts the values in a range that conform to a lookup of that range cell's value compared to another cell.
OMG, now that I look at it, that is totally confusing. Let me try to clarify a lot here.
Say we have Cell1, which will hold the counting formula. I have a list of values in a two-column table, Table1. The range, Range1 that Cell1 will be counting from is a range of cells that have List Validation in them. Table1 holds references to all values that can result from those Lists, in column 1. I have another cell, Cell2, which holds a number value. Column 2 of Table1 holds values that reference Cell2. I need to count the number of values from Range1 whose row matches in Table12 match the value in Cell2. Is there a way I can do this with COUNTIF without referencing each cell individually? Is there some shorthand (like Range.currentValue) that I can use to get the value of the cell currently being checked? The range is 11 rows long, and I need to do a second range that has 12 rows counted.
Man, I really don't know how to clarify that any more... I'll post this for now, in case anyone can understand what I'm saying and knows the answer, while I work on a sample spreadsheet I can upload.
I did my best to visually represent what I'm trying to accomplish:
http://gyazo.com/b83295baf3b156683a5c39b40c806504
Extended explanation: http://gyazo.com/4048802050e3dcfca7aee238acc2f7dd
Use a helper column, say, between the brown and the first blue or at the right of the setup. Use a vlookup like
=vlookup(brownvalue,BluetableRange,2,false)
Then do a countif on the helper column
=countif(HelperColumn,"<="&GreenCellAddress)
You can hide the column with the helper if it upsets your spreadsheet design.
You can (and probably should) use a helper column as Teylyn suggests. But, for when that may be inconvenient, you can also use an array formula:
=SUM(COUNTIFS(listlookupcolumn,rangeoflists,numbervaluecolumn,"<="&numbertomatch))
To enter it as an array formula, type "ctrl-shift-enter" after editing the formula, rather than just "enter"
Rough explanation: since rangeoflists is in a place where a single value is expected, the countifs is calculated once for each value, and the array of results is passed to sum. Use the "evaluate formula" feature to see the intermediate result array.
Afterthought: It occurs to me now that this does rely on listlookupcolumn containing unique values. (Almost certainly true in this example.) You can modify the formula a bit to get around this:
=SUM(SIGN(COUNTIFS(listlookupcolumn,rangeoflists,numbervaluecolumn,"<="&numbertomatch)))
The SIGN function will keep you from double counting.
Again, you must use "ctrl-shift-enter" for this to work. (Yes, as I'm sure others are ready to point out, you can also use the sumproduct hack in this instance.)

EXCEL - Find category by searching keyword from other worksheet

I want to get sales by category (states).
In Sheet1, there're state's names in row A (A1 to A6) and cities in the column.
Each cities belongs to states,
e.g.
Sydney belongs to NSW, and Melbourne & Geelong belong to VIC.
Then Sheet2 contains sales data like shown below.
I want to calculate sales by state each month.
At the moment, each cells between row D and row I has a formula like below;
(e.g. F5)
=IF(AND(ISERR(SEARCH("Brisbane",B5)),ISERR(SEARCH("Gold Coast",B5)),ISERR(SEARCH("Cairns",B5))),"",C5)
But I'm sure there would be better and more simple nifty way to do this. As shops increase, this current formula gets more complicated. So it's needed to be optimized.
I would like to make these calculation simple using vlookup or something.. but no luck so far.
Any advice, detailed if possible, would be greatly appreciated! Thank you in advance :)
You can do this with an array formula. For example, in D3 use:
=IFERROR(IF(INDIRECT("Sheet1!A"&MAX(IF(ISERROR(SEARCH("*"&Sheet1!$B$1:$D$6&"*",$B3))+(Sheet1!$B$1:$D$6=""),0,ROW(Sheet1!$B$1:$D$6))))=D$1,$C3,""),"Not found")
(To enter an array formula, you need to press Ctrl+Shift+Enter)
The SEARCH looks at the store name in B3 and compares it to all names in Sheet1!B1:D6 with a * wildcard before and after. This won't be an error if it matches.
Adding the +(Sheet1!$B$1:$D$6="") gives an OR the cell is blank (otherwise ** would match).
If it isn't an error, we'll get the ROW of the corresponding match and we take the highest (MAX) row match.
We then use INDIRECT to get the cell value in column A of Sheet1 (the State code) and compare that to the state in the top row of our column
This is wrapped in an IFERROR to tell us if our store doesn't match any city
Array formulas are a great tool, but a little confusing! Rather than work on a single cell, array formulas work on each cell of an array. Typically this is for counts, sums, averages, etc. By including “logic maths”, you can do some really strange things in a single formula. A good resource is [link]http://www.cpearson.com/excel/arrayformulas.aspx Always remember to use Ctrl+Shift+Enter or really strange things will happen!

Resources