I have requirement where I have range for which I want to perform count. Because there is a condition, I want to use COUNTIF/COUNTIFS function. In criteria, I want to use range as I have multiple value that can be matched. Following is an example
Values to be counted - APPLE, MANGO, ORANGE, MANGO, APPLE, APPLE, ORANGE, ORANGE
What I want is count for APPLE and ORANGE for example but I want to keep it generelized. That means in another column I want to put values for which I want count. So at a time I can put only APPLE, at another time APPLE, MANGO and so on. If I'm still not clear enough then in another words, I want a count of values which are determined by the values in another range.
I could not find any way to use range in the 'criteria' parameter of the COUNTIF/COUNTIFS function. I know I can use sum of multiple COUNTIF with different value in each 'criteria' but that becomes hardcoded and everytime I need to change the formula.
Can someone help with how can I use a range (instead of single value) in 'criteria' ?
perhaps
=SUMPRODUCT(COUNTIF(data_range,criteria_range))
Let's assume your data list is in column A and your "values to be counted" occupy, say, D1:D5.
In cell B1, use =IF(ISNA(VLOOKUP(A1,$D$1:$D$5,1,FALSE)),0,1). This will write 1 if A1 appears in D1:D5, 0 otherwise.
Copy this formula downwards. Note that it will return 0 for a blank cell so you can extend this formula as far as you like thereby future-proofing your sheet.
In another cell, sum column B, =SUM(B1:B...) Where B... is the end of the formula range.
I don't think you can arrive at the final formula in one step using arrays.
I suggest you investigate the Excel formula DCOUNT
http://office.microsoft.com/en-us/excel-help/dcount-HP005209049.aspx
Microsoft even use a fruit based example for you !
CountIf accepts a range, and a criteria. The criteria can reference a range.
For example:
=CountIf(A:A,"Apple") counts the number of occurrences of the word "Apple" in column A.
And:
=CountIf(A:A,B2) counts the number of occurrences of *whatever value is in Cell B2, in column A.
If you use two cells to define the search criteria, say, B2 and C2, you could do:
=CountIf(A:A,B2)+CountIf(A:A,C2)
Or using CountIfs:
=CountIfs(A:A,B2,A:A,C2)
If you must put both search criteria in a single cell (seems like a problem of bad worksheet structure, rather than any good design requirement), then you can modify the criteria of any of the above functions using string functions:
Ex: Say your criteria of Apple, Orange is a single cell, C2, delimited by the comma:
=CountIf(A:A,Trim(MID(C2,1,FIND(",",C2)-1))) + CountIf(A:A,TRIM(MID(C2,FIND(",",C2)+1,LEN(C2)))
I still think you're better served using a proper CountIfs or summing two CountIf with indpendent criteria ranges, rather trying to troubleshoot errors, or build complex formula (i.e., modify the above to work even if there is no comma, or a single value, etc....)
Related
I have a column on my worksheet that is supposed to be ranges of numbers like this (Random Digit Assignment).
Each cell are created by the ROW formula.
For Example
(E4): =ROWS(D4:D4)(D41000)&" - "&ROWS(D5:D5)(D51000) (but it does not matter)
Now, what I want is to search numbers within those ranges in cells.
Like I want to search 210 and the result that I want is 5
Is that possible? How?
You could use:
=MATCH(210,--LEFT(E3:E18,FIND(" ",E3:E18)))
If you don't have ms365 and you don't want to CSE this formula use:
=MATCH(210,INDEX(--LEFT(E3:E18,FIND(" ",E3:E18)),))
You can use the MATCH function in general for that purpose. If you had a separate column for start and end of range, then you could use two MATCH calls to find the closest start/end of range and then return the address of the lookup result. You can compare the closest start and closest end with the searched term and choose the row of the one which is closer. From there on, the final step is to just get the proper cell in the row you found.
I am straggling with some formula that I have a spreadsheet that contains two range of cells. What I want to do is,
I would like to create a search Box that will search a value from Range A and if found return range B value and also will count of range B value is repeated.
Below image is for what I mean
I used INDEX, MATCH and also IF Functions :( but not really get what I wanted.
I am poor in formula, so it would be great if someone can figure out what kind of functions I should use for this.
For information, it can be achieved through formula as below.
E3 houses the value being searched for e.g. "A"
In cell F3 insert following array formula which needs to be committed by hitting CTRL+SHIFT+ENTER simultaneously.
=IFERROR(INDEX($B$1:$B$1000,SMALL(IF(IFERROR(MATCH($E$3&$B$1:$B$1000,$A$1:$A$1000&$B$1:$B$1000,0),0)=ROW($B$1:$B$1000),ROW($B$1:$B$1000)),ROWS($A$1:A1))),"")
Copy down as much as you need.
You need to adjust 1000 to suit your data. It should match last row.
In cell G3 you can use following formula.
=IF(F3="","",COUNTIFS(A:A,$E$3,B:B,F3))
Copy down as much as you need.
I need to count all of the occurrences of a given value from a specific range of cells (containing strings or numbers), depending on a parameter stored in another cell.
I prepared a simple Excel table as an example (see attached image): let's say I want to count all of the occurrences of the VALUE "4" for the BASE "100". The result should be: 2 (C4 + C5).
Attached image
I tried to use COUNTIFS and FIND functions but with no results. The former only considers exact values (so the 4 in cell C5 will be ignored) while I seem to be unable to add another condition - the BASE column - to the latter.
Fact is I need to solve this with formulas only, no programming.
Thanks in advance for your help!
Use the SUMPRODUCT:
=SUMPRODUCT(($B$2:$B$10=100)*(ISNUMBER(SEARCH(4,$C$2:$C$10))))
There's a couple of other approaches, the simpler one is just to add another column which identifies matches for you, then have your count just sum the results of that column.
Solution image
So we put the values we want to find in some reference cells, the BASE match goes in G2, and the VALUE we're looking for goes in G3.
In column D we put a formula in D2:
"=IF(B2=$G$2,IF(ISERR(SEARCH($G$3,C2)),0,1),0)"
Returns 0 if the BASE matches and we can find at least one occurent of VALUE
B2=$G$2 - Does the BASE column match the BASE we're looking for
ISERR(SEARCH($G$3,C2)) - Does searching for the VALUE return an error (if it does, we know that VALUE isn't there)
Copy this formula to all the cells in column D, and then you can just use a simple SUM(D:D) to count the occurences where your conditions are met.
The neater but slightly more complex alternative is to use an array formula to do the match finding and counting all in one formula. This would look like this:
"{=SUM(IF(B:B=$G$2,IF(ISERR(SEARCH($G$3,C:C)),0,1)))}"
Pretty much the same as the formulas in column D, but now we use B:B and C:C in place of B2 / C2 etc. and stick the SUM around the whole thing. If you finish editing with Ctrl+Shift+Enter instead of just Enter, that'll make it an array formula.
Microsoft Array Formula Guidelines
NB: this WILL NOT count multiple occurences of 4 in a single VALUE cell.
p.s. Assuming you would want it to actually return 3 in this case (you missed the 4 in C7)
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.
I'm working on adding a collection of board games to our library.
I have a spreadsheet that lists more games than I intend to buy, but have them there to investigate. I have the prices for a couple of websites listed beside each game.
The problem is that I want a sum that doesn't include every game on the list. Instead, I want to add a column at the front that if I put an "X" indicating this is a game to get, then I want it to add the value for that. Only the values for rows that start with an "X" in column A will in added together, instead of everything.
I was hoping to do this with a formula instead of just choosing a basic =SUM formula and selecting only a few cells at a time. I assume a =SUMIF might be the answer, but I have yet to figure out how to get this to work.
Please try:
=SUMIF(A:A,"x",B:B)
where B:B is the column with the values. I suspect your difficulty may have been that when using text as the 'trigger' it needs to be in double inverted commas.
Or you might sort by ColumnA and just use =SUM as far down as there are xs.
Or filter on ColumnA to select x and Autosum ColumnB but change the 9 to 109.
SUMIF requires at least 2 parameters, and at most 3. In your case, you will need to use 3.
If you type the formula in excel, you will see a little balloon indicating:
=SUMIF(Range, Criteria, [Sum_Range])
Range is the range where you want to apply the condition, in your case, A:A.
Criteria is the condition applied to the range, in your case "x".
[Sum_Range] is the range to sum, after applying the condition.
The above will sum all the cells in the range [Sum_Range], for which the cells of Range satisfies the condition Criteria.
Translating that into an actual formula, you get pnut's formula:
=SUMIF(A:A,"x",B:B)
The above will sum all the cells in the range B:B, for which the cells of A:A satisfies the condition x (SUMIF considers the criterion as being 'equal' so it will sum only when they are equal to the criteria).
As an extra, you can change the condition to mean 'not equal' by using something like this: =SUMIF(A:A,"<>x",B:B) (the <> means not equal to in Excel).