I want to SUMPRODUCT to ranges but only if there is no 0.
tried =SUMPRODUCT(--(CN12:CN16="<>0");I4:I8) but the results gets 0,
i have to ranges: CN12:CN16 and I4:I8, and CN12:CN16 can sometimes contain zeros. then i do not want to take that into the calculations and multiply with the value in I4:I8.
Any suggestions
Use this formula to get the SUMPRODUCT:
=SUMPRODUCT(CN12:CN16, I4:I8)
This evaluates AS:
=CN12*I4 + CN13*I5 + CN14*I6 + CN15*I7 + CN16*I8
So if one of the values equals to 0 that specific product equals to 0, and the rest of the products add to the total.
Here you have a REFERENCE to evaluate if any of the cells in your range equals with zero.
Do you actually want to use CN12:CN16 values in the calculation or are they simply a criteria range? In SUMPRODUCT you don't need the quotes so this might be what you need -
=SUMPRODUCT(--(CN12:CN16=<>0);I4:I8)
although SUMIF will get you the same thing more easily
=SUMIF(CN12:CN16;"<>0";I4:I8)
So solved it like this: =SUMPRODUCT(CN13:CN17;$I4:$I8)/SUMIF(CN13:CN17;"<>0";$I4:$I8)
As some of you wrote SUMPRODUCT gets zero if there is a zero in a list and then i check that list again in the SUMIF when i divided with the I4:I8. Maybe I was a little unclear in my description of the problem.
Thanks for your help.
Related
I was researching a way to count the number of zeroes in a column of data, even if the data gets filtered. I found the following solution:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1)),ISNUMBER(SEARCH("Pear",B2:B18))+0)
Where, B2:B18 is the total list of data and "Pear" is the criteria being counted.
Can someone explain how this formula is accomplishing this task?
Is there a simpler way of doing this?
I was able to determine that:
SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1))
is used to return an array of which cells are visible and hidden in the range. 1 is returned for visible and 0 is returned for hidden.
ISNUMBER(SEARCH("Pear",B2:B18))+0)
is used to return an array of which cells contain "Pear". If "Pear" is found, 1 is returned, else 0.
SUMPRODUCT(arrayofvisiblecells , arrayofcellswithPear)
is used to sum all of the times when the cell is visible AND "Pear" is present. 1*1 else you will be multiplying by a 0.
With Office 365 we can finally get rid of the volatile OFFSET by using BYROW instead:
=SUMPRODUCT(BYROW(B2:B18,LAMBDA(a,SUBTOTAL(3,a))),ISNUMBER(SEARCH("Pear",B2:B18))+0)
The BYROW(B2:B18,LAMBDA(a,SUBTOTAL(3,a))) does the same as SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1)) without being volatile.
=SUMPRODUCT(SUBTOTAL(3,OFFSET(Sheet1!$A$1:$A$1006,ROW(Sheet1!$A$1:$A$1006)-MIN(ROW(Sheet1!$A$1:$A$1006)),,1)),ISNUMBER(SEARCH(B861,Sheet1!$A$1:$A$1006))+0)
B861 is what ever cell you are referencing.
I was wondering how to represent the criteria argument in the function =SUMIF(range, criteria) as instead of ">0" which represent greater than zero, which would add all numbers in the range that are greater than zero. I was wondering how to make it within the range of zero to 8, so "8>0", or something, but I have been googling for hours and cannot find a solution that doesn't involve doing whacky things with SUMIFS which involves other arrays which I do NOT want to get into because I feel there's a simple solution to this that I'm missing...
Theres ">=NUM" "<=NUM" ">NUM" and "<.NUM"
how do you make it require two of these?
Is there any documentation on this anywhere?
I agree with #user3240704 that SUMIFS is the way to go.
If you insist on using SUMIF only then you can use the following logic:
take the sum of the entire range
deduct the sum of values <-10
further deduct the sum of values >0
Which is the inverse of saying
only the sum the values >=-10 and <=0
The formula is:
=SUM(A1:A11)-SUMIF(A1:A11,">0",A1:A11)-SUMIF(A1:A11,"<-10",A1:A11)
E.g.
More info here
=SUMIFS(A1:A11,A1:A11,">=-10",A1:A11,"<=0")
SUMIFS has many (in this case two) conditions, broken down as follows:
=SUMIFS(A1:A11 - SUM() whatevers in A1:A11
, - That match the following conditions
A1:A11,">=-10" - ALL numbers in A1:A11, that are greater than OR equal to -10
, - AND
A1:A11,"<=0" - ALL numbers in A1:A11, that are less than OR equal to 0
)
How do I average a list of numbers whose values are greater than 0? I know I can use AVERAGEIF function in Excel
My data is located in A2, A5, A6, A10, A17.
I only want to average it if the data is greater than 0.
Since my data is not an range, I am not able to use AVERAGEIF Function range.
Need some help on this.
EDIT
For example,
I tried with three numbers:
1) 98.068 and 98.954 and 0 so my forumla looked like this:
=AVERAGE(IF(N(OFFSET(A2,{0,5,10},))>0,N(OFFSET(A2,{0,5,10},))))
The answer came out as 99.106. Not sure why.
A few options:
1)=SUM(SUMIF(INDIRECT({"A2","A5","A6","A10","A17"}),">0"))/SUM(COUNTIF(INDIRECT({"A2","A5","A6","A10","A17"}),">0"))
2)=AVERAGE(IF(N(INDIRECT({"A2","A5","A6","A10","A17"}))>0,N(INDIRECT({"A2","A5","A6","A10","A17"}))))
3)
=AVERAGE(IF(N(OFFSET(A2,{0,3,4,8,15},))>0,N(OFFSET(A2,{0,3,4,8,15},))))
2) and 3) must be committed as array formulas**
Regards
(0) A simple method
=SUM(A2*(A2>0),A5*(A5>0),A6*(A6>0),A10*(A10>0),A17*(A17>0))/SUM(A2>0,A5>0,A6>0,A10>0,A17>0)
(4) A more general method
=SUM((A1:A20>0)*A1:A20*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))/
SUM((A1:A20>0)*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))
The second one is an array formula and must be entered with CtrlShiftEnter
If it's possible to have text in the cells rather than numbers, then this should replace the first formula:-
=SUM(N(A2)*(A2>0),N(A5)*(A5>0),N(A6)*(A6>0),N(A10)*(A10>0),N(A17)*(A17>0))/SUM(N(A2)>0,N(A5)>0,N(A6)>0,N(A10)>0,N(A17)>0)
(I haven't used N in the > brackets in the numerator because I reason that if A2 etc. is text, the product will always be zero)
I can't persuade N to work with arrays in the second formula, so at the moment I have the rather lengthy
=SUM((IF(ISNUMBER(A1:A20),A1:A20,0)>0)*IF(ISNUMBER(A1:A20),A1:A20,0)*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))/
SUM((IF(ISNUMBER(A1:A20),A1:A20,0)>0)*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))
but I have tested it on text values and negative numbers and it does seem fine.
The only exception is if one of the cells contains TRUE. In this case the first formula will count it as 1, the second formula will ignore it.
How to use SUMIF formula in Excel cell that must sum over a given range and instead of finding for a single value, it should find multiple values?
For finding a single value, I use:
=SUMIF(A4:A100;"1";B4:B100)
Now I need to sum over if the column A holds 1 or 2, like:
=SUMIF(A4:A100;"1" OR "2";B4:B100)
The cell A1 will hold the criteria as a text, here it would be 1;2.
It should return same as
=SUMIF(A4:A100;"1";B4:B100) + SUMIF(A4:A100;"2";B4:B100)
but I need a formula that can take any number of criteria (1,2,3,... or more).
What's the syntax? I'm not able to use VBA here.
To sum for 1 or 2 try this version
=SUM(SUMIF(A4:A100;{1;2};B4:B100))
SUMIF will return an "array" of two results so you need SUM to sum that array for the total for 1 and 2
You can add as many numbers as you like e,g,
=SUM(SUMIF(A4:A100;{1;2;3;4};B4:B100))
or with numbers listed in a range like Z1:Z10
=SUMPRODUCT(SUMIF(A4:A100;Z1:Z10;B4:B100))
I don't think there is a way to do OR within a single statement like this. You can use SUMIFS for multiple conditions where all need to be true, but in this case you would just need to add together multiple SUMIF statements:
=SUMIF(A4:A100,"1",B4:B100)+SUMIF(A4:A100,"2",B4:B100)
Since "1" and "2" are mutually exclusive:
=SUMIF(A4:A100,"1",B4:B100)+SUMIF(A4:A100,"2",B4:B100)
i think you should define a range, let's say keys where you keep all values for which you want to sum. so in this range you keep 1 and 2 and can modyfy it whenever you want. then you add a flag column with formula IFERROR(IF(MATCH(A4,keys,0)>0,1,0),0) - now you have column in which 1 is for the values you want to sum.
this works with multiple text evaluation
=sumif(M4:M206,"Sat",O4:O206)+sumif(M4:M206,"Sun",O4:O206) // add here more + + +
I'm looking to do the equivalent of SUMPRODUCT but with division. Is there a way to add the results from dividing two arrays?
Example: Column A has the "life" of an asset in years (10, 20, 10). Column B has the Value of the asset (10,000, 20,000, 20,000). I want to add the result of (10,000/10) + (20,000/20) + (20,000/10) = 4,000, but for the formula to be dynamic as I add rows with life and value.
Thanks in advance.
Since the division is the inverse of the multiplication, you can use this:
=SUMPRODUCT(1/A1:A3, B1:B3)
You can do that with this formula
=SUMPRODUCT(B2:B10/A2:A10)
no blanks or zeroes allowed in the column A range...
edit: missed dynamic part....either use dynamic named ranges....or you can use this array version to allow up to 1000 rows, where later ones are blank
=SUM(IF(A2:A1000<>0,B2:B1000/A2:A1000))
confirmed with CTRL+SHIFT+ENTER
Actually the best formula is this one:
=SUMPRODUCT(SUM(E2:E10))/(SUM(D2:10))
You can also combine the formula with another one like the following:
=SUMPRODUCT(SUM(E2:10))/(count(D2:D10))
Good luck