I have this Array formula that Works good:
{=SUM(IF(Range1="L";Range*Range))/SUM(IF(Range1="L";Range))}
But if I change SUM(IF to SUMIF doesn't work I don't know why.
{=SUMIF(Range1;"L";Range*Range)/SUMIF(Range1;"L";Range)}
And I want to put SUMIFS, because I want to add a new IF in the first formula, like this:
{=SUMIFS(Range*Range;Range1;"L";Range2;"N")/SUMIFS(Range*Range;Range1;"L";Range2;"N")}
What I can do to put two ifs in the array formula?
SUMIF and SUMIFS are already array formulas (somewhat) and they don't take well to range multiplication. You can use the two criteria in a SUM(IF, or in a SUMPRODUCT, e.g.
=SUM(IF(AND(Range1="L",Range2="N"),Range*Range,0))
=SUMPRODUCT((Range1="L")*(Range2="N")*Range*Range)
Related
=SUMIF(A1:A14, "102000*", B1:B14)
Why it cannot filter the value starts with 10200?
An array (CSE) formula solves the issue:
How it works:
Suppose you want to add numbers like 1020001, then enter it as criteria in cell D74, and use this formula.
{=SUM((B74:B82)*(--(A74:A82=D74)))}
If you have more criteria, like I've shown in D74 & in E74, then use this one in C74.
{=SUM((B74:B82)*(--(A74:A82=D74)+(--(A74:A82=E74))))}
N.B.
Finish formula with Ctrl+Shift+Enter.
You may adjust cell references in the formula as needed.
You are better off creating a new column using the formula
left(a1,5)
Then base the sumif off that new column.
If you want to count the number of occurences, you can use
=SUMPRODUCT(--(--LEFT(A1:A7,5)=10200))
and if you actually want to sum values, use
=SUMPRODUCT(--(--LEFT(A1:A7,5)=10200)*(B1:B7))
I have an array formula that refers to a drop down cell ($AG$7) to determine which cells to evaluate. This works well, however, I need to include an additional item in the drop down which is "All".
When this is selected, I want the array formula to use "*" to return all instances from the array, but i can't get it to work.
This is the formula I'm currently using;
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")=$AG$7),1,0))}
I've tried using
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7),1,0))}
and
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7&"*"),1,0))}
But these don't work.
Does anybody have any ideas?
Thanks
A explicit = comparison cannot use wildcards. COUTIFS and SUMIFS can. As far as I see, you want to count only (conditional sum 1 and 0).
Problem is, COUTIFS and SUMIFS will not deal with INDIRECT ranges. But INDIRECT can and should (because of its volatile bahavior) often replaced by INDEX- MATCH.
So:
=COUNTIFS(tblSkillsMatrix[role],[#role],INDEX(tblSkillsMatrix,,MATCH($V$2,tblSkillsMatrix[#Headers],0)),"*"&$AG$7)
If $AG$7 is empty then it counts independent of the column named in $V$2.
Btw.: Within a table (ListObject) this needs not be entered as a array formula.
This is not 100% replacement of your formula since it not works if $V$2 is empty and so no table column title is given. Your formula will then look at all columns but this is not possible using COUNTIFS where each additional range must have the same number of columns as the criteria_range1 argument. So if $V$2 shall also can be empty, then this will not work.
If so then you could use
{=SUM((tblSkillsMatrix[role]=[#role])*(LEFT(INDIRECT("tblSkillsMatrix["&$V$2&"]"),LEN($AG$7))=$AG$7))}
Advantage: both $V$2 and $AG$7can be empty.
Disadvantage: Volatile behavior of INDIRECT and this formula then must be a array formula even in a ListObject-table. It must be confirmed using Ctrl+Shift+Enter.
I know that a formula can be applied on a range of cells by utilizing an intermediate column, but can I directly specify a range in a formula somehow?
E.g., is it possible to do something like this, to get the sum of the results of dividing each cell in E12-E26 by each cell in C12-C26:
=SUM(E12/C12:E26/C26)
An answer, either positive or negative, would be accepted.
You can do what you are wanting to do with an Array formula or CSE formula (Different name for the same thing). To do this, enter:
=SUM(E12:E26/C12:C26)
Then, instead of hitting "Enter" on the keyboard use Ctrl+Shift+Enter (CSE). This will put squirrely brackets around the formula and will apply the division to each pair in the range and then sum the results.
You could also use =SUMPRODUCT() for this, which essentially acts like an array formula, but with the Ctrl+Shift+Enter nonsense:
=SUMPRODUCT((E12:E26)/(C12:C26))
Sumproduct is useful since it will do logic inside the parantheses first across an array/range of cells then sum up the results. You can pull of some cool stuff with the formula, but it's also a beast and cat get out of control pretty easily.
Tryingto CountIf with Exclusions and multiple criteria,
Here's an example of just multiple critera:
=SUM(COUNTIFS(A1:A9,"YES",B1:B9,{"JOHN","GEORGE","RINGO","PAUL"}))
Here's an example of just exlusion:
=SUM(COUNTIFS(A1:A9,"YES",B1:B9,"<>*JOHN*"))
And here's the sum we're currently got but not working:
=SUM(COUNTIFS(A1:A9,"YES",B1:B9,{"<>*JOHN*","<>*GEORGE*","<>*RINGO*","<>*PAUL*"}))
When criteria becomes too complex for COUNTIFS, you can often use an array formula. I think the following array formula will achieve your goal...
=SUM(IF(A1:A9="YES",1,0)*(IF(ISNUMBER(FIND("JOHN",B1:B9)),0,1))*(IF(ISNUMBER(FIND("GEORGE",B1:B9)),0,1))*(IF(ISNUMBER(FIND("RINGO",B1:B9)),0,1))*(IF(ISNUMBER(FIND("PAUL",B1:B9)),0,1)))
Make sure to use CTRL+SHIFT+ENTER to enter the array formula.
Is it possible to combine AND (or OR) statement criteria to avoid repeating a cell name?
For example, I want to see if cell C2 contains the any of the numbers 2,3,5,7, or 10. I want to avoid writing
IF(AND(C2=2,C2=3... etc.
and simplify it to an array of the numbers like
IF(AND(C2=[2,3,5,7,10]...
Unfortunately, I have a lot more than just 5 numbers to add so it's getting be very laborious. Anyone have an easier way than repeating the cell name=__ over and over?
You can use an "array constant" like this
=IF(OR(C2={2,3,5,7,10}),"Yes","No")
.....or for a large set of numbers you could put all the numbers in a cell range, e.g. Z2:Z100 and do the same
=IF(OR(C2=$Z$2:$Z$100),"Yes","No")
although when you use a range rather than an array constant the formula becomes an "array formula" so needs to be confirmed with CTRL+SHIFT+ENTER
perhaps better to use COUNTIF and avoid "array entering"...
=IF(COUNTIF($Z$2:$Z$100,C2)>0,"Yes","No")
=IF(ISERROR(MATCH(C2,{2,3,5,7,11},0)),"no","yes")
No need to enter this as an array formula. How it works: MATCH returns a #N/A! error if it can't find the lookup value in the lookup array. ISERROR catches this.
But as barry houdini suggests, you may want to put your numbers in some range e.g. Z1:Z5 instead of hard-coding them into your formula. So you would have this formula instead:
=IF(ISERROR(MATCH(C2,Z1:Z5,0)),"no","yes")