Sumproduct Excel one condition two columns to multiply and add - excel

I am trying to use excel to calculate how much of a number of components from bills of materials (BOMs) are used per month.
So I have several columns of components but a component can appear in several columns. Offset from these columns is the quantity of that component in the BOM and in another column are the sale quantities. Is SUMPRODUCT the correct formula to use?
I have tried:
=sum(sumproduct((B2:B10="Component1")*(L2:L10)*(AH2:AH10)), sumproduct((C2:C10="Component1")*(M2:M10)*(AH2:AH10)))
B and C columns contain the component codes, L and M the component quantity per BOM and AH the sales quantity.
What am i doing wrong? Will this work? The quantities this returns are not correct.
Thanks,

In SUMPRODUCT, you should use comma or semicolon depending on your locale to separate the arrays being multiplied instead of using multiplication operator (*).
=SUM(SUMPRODUCT(--($B$2:$B$10="Component1"),$M$2:$M$10,$AH$2:$AH$10),SUMPRODUCT(--($B$2:$B$10="Component1"),$L$2:$L$10,$AH$2:$AH$10))
Since ($B$2:$B$10="Component1") evaluates to an array of TRUE & FALSE, you use -- to convert that to 1 or 0. You can also multiply it by 1.
=SUM(SUMPRODUCT(1*($B$2:$B$10="Component1"),$M$2:$M$10,$AH$2:$AH$10),SUMPRODUCT(1*($B$2:$B$10="Component1"),$L$2:$L$10,$AH$2:$AH$10))

SUMPRODUCT treats array entries that are not numeric as if they were zeros. The first parameter in each of your sumproducts will evaluate to either TRUE or FALSE but they are not strictly numeric. You can coerce them to numbers - TRUE = 1, FALSE = 0 by:
Multiplying by double negative
Multiplying by 1 or
Adding 0
So change your formula to:
=SUM(SUMPRODUCT(--(B2:B10="Component1")*(L2:L10)*(AH2:AH10)),
SUMPRODUCT(--(C2:C10="Component1")*(M2:M10)*(AH2:AH10)))

Related

Counting based on two columns in Excel

I have the following table in Excel:
Name Col_A Col_B
Michael Some_value
Alex Some_value Some_value
Jennifer
I want to count in a single cell (without adding any columns to assist me) how many names I have that have at a value at least in one of the columns A or B. So in this case the result will be 2.
I tried to do it with COUNTIFS and COUNT (IF) but it seems to cover only one column at a time.
Using MMULT()
• Formula used in cell F4
=SUM(N(MMULT(--(D4:E6<>""),{1;1})>0))
So, we can use either -- or N() which means
The double unary (also called a double negative) is an operation used
to coerce TRUE FALSE values to ones and zeros in more advanced
formulas, especially formulas that work with arrays.
While N() function converts non-number values to a number, dates to
serial numberss, TRUE to 1 and anything else to 0
Note: Source for -- taken from exceljet.net

How to regexmatch a range?

I am trying to take a data from a table and get the value of how much a class gets a point. I used VLOOKUP to do this, but the problem is that I have to tell the sheets on which class gets how much.
The data:
Your data seems to be setup in a way that unnecessarily complicates things.
kelas-column isn't showing the class, but name and class. For easy use in calculation this would better be divided in two columns: name | class
poins-column seems to be numbers formatted as text (judging by the leading +) if it was showing the number only and the class would show the actual class, a simple SUMIF would solve your problem.
Now it's still doable using SUMPRODUCT:
=SUMPRODUCT(--(A17=RIGHT($B$2:$B$11,2)),--($D$2:$D$11))
The first part checks if the search value A17 equals the last 2 digits in range B2:B11 (the $'s in the formula are to lock the range when dragging the formula down or aside).
This results in an array of TRUE's and FALSE's which is converted to 1's and 0's by the leading --.
The second part simply converts the text values to numbers using the same logic as with the TRUE's and FALSE's, using the --.
SUMPRODUCT multiplies the first array with the second array and adds it all up.
If a condition is true it multiplies the value of the points column by 1 (equals the points), if false it multiplies by 0 (equals 0).
In the end it sums all values meeting given condition.

SUM numbers, but when 0, add 8 instead

I'm trying to write a SUM(IF(zero, add 8), A1:G1) kind of excel function.
What it should do:
If the cell contains a number, add that number to the sum.
If the cell contains a number = 0, add 8 to the sum.
if the cell is empty, add nothing to the sum
I have tried using SUMIF, but it only "adds the numbers if they meet a criteria", and I rather need "add this when the criteria is met"
You could just make a longer formula:
=SUM(A1:G1)+COUNTIF(A1:G1, 0)*8
The first sum will only do your numbers ignore blanks and 0's, the second part counts the number of 0's and multiplies it by 8.
You can do this with the following formula:
=SUMIF(A1:G1,">0")+8*COUNTIFS(A1:G1,0,A1:G1,"<>")
should be self-explaining :)
Method 1
If you can spare another column, just use an IF statement to replace all 0's by 8's and blanks by 0's (not really necessary) in a new column
=IF(A1=0,8,A1) and take a SUM of this column.
Method 2
Just SUM over your original data, count the number of zeros in your data and multiply this number by 8.
=SUM(A1:A10)+8*COUNTIF(A1:A10,"=0")
Note: The data is in A1:A10 in this case.

Sum + Countifs formula not working

I'm using Google Sheets and am trying to get this formula to work to give the me the following count:
Count when Column T = Kenneth AND Column U = (Pending OR Contacted) AND Column W has a date that falls between the dates shown in B14 and B15.
This is what I have so far:
=sum(countifs(Users!$T:$T,"Kenneth",Users!$U:$U,{"Pending","Contacted"},Users!$W:$W,">"&$B14,Users!$W:$W,"<="&$B15))
This is giving me the correct count for Pending alone but it is ignoring all the Contacted rows so somehow it is not recognizing that OR operator.
COUNTIFS (and SUMIFS) do not support array arguments for the conditions. You will need to resort to summation of COUNTIFS:
=COUNTIFS(Users!$T:$T,"Kenneth",Users!$U:$U,"Pending",Users!$W:$W,">"&$B14,Users!$W:$W,"<="&$B15)+COUNTIFS(Users!$T:$T,"Kenneth",Users!$U:$U,"Contacted",Users!$W:$W,">"&$B14,Users!$W:$W,"<="&$B15)
or a different approach, eg:
=COUNTIF(FILTER(Users!$T:$T,(Users!$U:$U="Pending")+(Users!$U:$U="Contacted"),Users!$W:$W>$B14,Users!$W:$W<=$B15),"Kenneth")
Use arrayformula, you can sum the boolean values multiplied against each other.
=arrayformula(sum((T:T="Kenneth")*(U:U={"Pending","Contacted"})*(W:W>=B14)*(W:W<=B15)))
A boolean true is 1 and a false is 0. Anything multiplied against a zero is zero so all conditions must be true to add another 1 for each row.
        

Excel Condition missplacing

I am trying to make an average of multiple cells, and I want to ignore to zero cells.
Here is my formula =IFERROR(AVERAGEIF(L4:L10;L12:L18;L20:L26;L28:L34;L36:L37);"") and I don't know where to put the condition to ignore zero "<>0" . Am I doing something wrong?
Assuming you only have positive values and zeroes you can average without zeroes, for non-contiguous ranges using this syntax
=IFERROR(SUM(L4:L10;L12:L18;L20:L26;L28:L34;L36:L37)/INDEX(FREQUENCY((L4:L10;L12:L18;L20:L26;L28:L34;L36:L37);0);2);"")
The FREQUENCY part gives you a two element array, one being the count of zeroes, the other the count of positive values, INDEX then retrieves the second of those (the number of positive values), so if you divide the sum by that count you get the average excluding zeroes. FREQUENCY function (unlike AVERAGEIF) accepts a non contiguous range argument (a "union")
....but if you can identify which rows to exclude by using values in another column then it's easier with AVERAGEIFS, e.g. if on the excluded rows, e.g. in K11, K21, K35 etc. they all have the value "Total" you can use this version:
=IFERROR(AVERAGEIFS(L4:L37;L4:L37;"<>0";K4:K37;"<>Total");"")
adjust depending on the exact text, wildcards are possible
Here is another way using SUMIF and COUNTIF.
Example data:
Values
1
-3
0
5
777
3
0
0
8
text
4
5
6
0
6
7
Formulas:
B18=SUMIF(A2:A17,"<>0",A2:A17)-SUM(A6,A11,A15)
B19=COUNTIF(A2:A5,"<>0")+COUNTIF(A7:A10,"<>0")+COUNTIF(A12:A17,"<>0")
B20=B18/B19

Resources