Excel: Scalar product of two ranges - excel

I am trying to find a proper way to calculate the scalar product of two ranges. For instance, the product of A1:A3 and B1:B3 would be A1*B1 + A2*B2 + A3*B3. Is there a good way to do this? Hardcoding this calculation is quite a tedious thing to do with large ranges.

Use this one
=SUMPRODUCT(A1:A3,B1:B3)

SUMPRODUCT formula – syntax and usage
Excel SUMPRODUCT formula - tutorialThe sum-product formula syntax is very simple. It takes 1 or more arrays of numbers and gets the sum of products of corresponding numbers.
The syntax is =SUMPRODUCT (list 1, list 2 ...)

Update on 11/30/2022
Considering the Excel Spill feature, now you can use SUM for most of the cases SUMPRODUCT was used, for example:
=SUM(A1:A3*B1:B3)
Here is the output:

Related

Compare multiple columns as pair-wise for Excel/Google Sheets

I am new to Excel/Google Sheets. I have a difficulty of writing a formula to compare columns as a pair-wise since the formula would be
so big as the day goes.
For example, there're 2 main columns Foo and Bar. I want to find the total number of days that Foo
and Bar are equal so the current formula is =IF(A3 = G3, 1, 0)+IF(B3 = H3, 1, 0)+IF(C3 = I3, 1, 0)+...
But this is kind of tedious because there're ~40 days to compare with. Are there any other alternatives
to write a formula in efficient way? Either Google-App-Scripts or Excel Formula is appreciated.
Cheers!
Give a try on below google-sheet formula. Adjust ranges as you need.
=ArrayFormula(SUM(IF(A3:E3=G3:K3,1,0)))
Assuming that you're needing to get such a total for each row and not merely a single row, try this:
=ArrayFormula(IF(A3:A="",,MMULT(IF(A3:F=G3:L,1,0),SEQUENCE(COLUMNS(A:F),1,1,0))))
Of course you will need to adjust the three ranges to match your own FOO and BAR ranges.
This one formula will produce all results for all rows.
The MMULT function is tricky to explain to those as yet unfamiliar with it. But it's a powerful tool. I'll add a picture I created that may best explain what it does:
By making the second matrix a simple SEQUENCE of 1s as long as the other matrix is wide, we wind up multiplying everything by 1 before adding together. And since anything multiplied by 1 is itself, this combination serves only to do a row-by-row add.
Things to keep in mind with MMULT:
1.) Every cell in every matrix must be a number or it will produce an error.
2.) As in the above formula, there are ways to use either/or conditions to turn every cell in a matrix into a number.

SUMPRODUCT with Dates for Criteria

I am trying to obtain an average of an array of fields with the following simple formula
=SUMPRODUCT(Main!BA:BA, Main!CY:CY, --(Main!D:D >=D3, Main!D:D <=E3))
I'm getting a #DIV/0! error. I have no clue why it's dividing anything. Please help!
Basically, how can I get the sum product of columns D vs E between the dates 11/05 to 11/27.
You need to use * or + depending on whether you want AND or OR.
=SUMPRODUCT(Main!BA:BA, Main!CY:CY, (Main!D:D >=D3)*(Main!D:D <=E3))
One more note:
You want to limit the references to only that with data as this formula will do a lot of unneeded calculations.
From looking at your worksheet, you want this:
=SUMPRODUCT(D:D*E:E*(C:C>=$C$27)*(C:C<=$C$49))

Summing together 2 or more VLOOKUPs in Excel

I have a cell which needs to sum together 3 different values, but I don't want to use relative/absolute cell references because the source data changes every year so the cell references would need re-pointing every year.
I've used VLOOKUPs for cells which only need to show 1 value and that's all fine, but I cannot find a way to add together the outcomes of 2 or more VLOOKUPs. Also, each of the 3 values have different criteria, and I think I therefore need 3 separate VLOOKUP functions.
Is there a way of doing this?
This is the formula I've used, which returns a '#N/A' error:
=vlookup("10000",datatable,3,false)+vlookup("10001",datatable,3,false)+vlookup("10002"),datatable,3,false)+...etc etc etc.
Many thanks in advance
Rob
Here is a simple example of summing 3 VLOOKUPs:
=SUM(VLOOKUP("A",A1:B3,2,FALSE),VLOOKUP("E",A5:B7,2,FALSE),VLOOKUP("I",A9:B11,2,FALSE))
I put 3 simple tables, each 3 rows and 2 columns, and added the lookup values together. So I look up A and return 1, E and return 5, I and return 9. Then I sum them and return 15. :-)
Providing the only part to vary is the lookup_value (as appears to be so in your case) then, instead of writing multiple distinct VLOOKUP clauses followed by summing them (which could result in an extremely long construction indeed), you can use a single, equivalent VLOOKUP set-up.
So instead of, for example:
=VLOOKUP("X",DataTable,3,FALSE)+VLOOKUP("Y",DataTable,3,FALSE)+VLOOKUP("Z",DataTable,3,FALSE)
we can use the shorter:
=SUM(VLOOKUP(T(IF(1,{"X","Y","Z"})),DataTable,3,FALSE))
or, for more flexibility, if we have "X", "Y" and "Z" within a contiguous range somewhere within the worksheet, e.g. H1:H3, then:
=SUM(VLOOKUP(T(IF({1},H1:H3)),DataTable,3,FALSE))
If the criteria are not text strings, but numerics, then we can use N instead of T: for example, if we were looking for, not "X", "Y" and "Z", but 1, 2 and 3, then we would use:
=SUM(VLOOKUP(N(IF(1,{1,2,3})),DataTable,3,FALSE))
or:
=SUM(VLOOKUP(N(IF({1},H1:H3)),DataTable,3,FALSE))
If our criteria comprise a mixture of text and numerics, e.g. "X", 2 and "Z", then we need a slightly different approach, though I will leave that to another post!
References:
https://excelxor.com/2014/09/05/index-returning-an-array-of-values/
Regards
Good heavens. Stop using VLOOKUP, everyone. INDEXtogether with MATCH is cleaner, neater and less prone to errors.
Now, for what you are doing, you don't need either. Why not check out SUMIFS
In your case it would look something like this
=SUMIFS(Sumcolumn;Criteriacolumn;10000;Criteriacolumn2;10001,...)
And, even if your sumcolumns are different from each other - it is still easier to sum several sumifs than it is to sum several vlookups, since vlookup will throw a #N/A if empty reference, whereas sumifs will return 0. If you have a desire to be extra efficient with just one formula, use SUMPRODUCT - however that is a formula that needs some practice to write.

Excel - SUMIFS for multiple columns

I need to sum the values of several columns, if other cells in the same row match a predefined criteria. The working formula for only 3 columns is the following:
=SUM(SUMIFS(‘Sheet1'!W:W; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!X:X; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!Y:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4"))
I will need to use the formula for several cells (and sum more than 10 columns per time) and I will need to change the columns manually, so I need the same formula in the following way:
=SUMIFS(‘Sheet1'!W:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4")
,but currently this formula leads to a "#VALUE!" error. The reason for that is (I assume) the use of multiple columns "W:Y"
Can you suggest a workaround?
I would suggest to use SUMPRODUCT rather than SUMIFS. You can build something like that :
=SUMPRODUCT((B1:B1048575="Sales")*(C1:C1048575>=4)*(W1:Y1048575))
The downside of SUMPRODUCT is that you can't use a whole column (for example you cannot write SUMPRODUCT((B:B="Sales"...)), this would generate an error).
Hope this helps.
I suggest you add a column with the sum('sheet1'!W:Y) and then use sumifs on this columns. It is a two step way but it will give the result you expect
Here's what I have :)
=SUM(SUMIFS('WTD Raw'!R:R,'WTD Raw'!E:E,"Kindle-Customer Care",'WTD
Raw'!J:J,"Week27",'WTD Raw'!H:H,'PassRate | July'!G8) + SUMIFS('WTD
Raw'!R:R,'WTD
Raw'!E:E,"Kindle-Technical Support",'WTD Raw'!J:J,"Week27",'WTD
Raw'!H:H,'PassRate | July'!G8))
Instead of using ";" use the Mathematical Operators for it to work.

Find Minimum Value Based on 2 Criteria (Excel 2013)

Looking to find the max value in a column based on two sets of criteria
So the logic would be: Find the minimum value in column M, where the value in column A matches column N, and the value in Column Y is less than 318.
I've tried using an array formula like this but it doesn't seem to be working/is to memory heavy to run:
=MIN(IF(AND(N:N=A2,Y:Y<=318),M:M))
is there a simpler way? or perhaps a UDF that could work?
Thank you for your help!
You can't use AND in these type of formulas because it only returns a single value rather than the required array.
Here are three possible working versions:
1.) Use * to simulate AND
=MIN(IF((N:N=A2)*(Y:Y<=318),M:M))
confirmed with CTRL+SHIFT+ENTER
2.) Use multiple nested IFs
=MIN(IF(N:N=A2,IF(Y:Y<=318,M:M)))
confirmed with CTRL+SHIFT+ENTER
3.) Use AGGREGATE function
=AGGREGATE(15,6,M:M/(N:N=A2)/(Y:Y<=318),1)
The advantages of this approach are that you don't need "array entry", and it can ignore any errors in the data
Either way it's best to reduce the ranges sizes if you can because it might be slow with whole columns
Give this a try and adjust ranges to suit. Try not to use whole column references:
=SMALL(INDEX(($N$2:$N$101=A2)*($Y$2:$Y$101<=318)*$M$2:$M$101,),1+ROWS($M$2:$M$101)-COUNTIFS($N$2:$N$101,A2,$Y$2:$Y$101,"<=318"))
If you are using the whole column to pick up new data as it is added, consider using Dynamic Named Ranges instead
When things get this complex, I'll usually break it down and setup smaller/simpler formulas in seperate columns.
In other words, you have data in columns A through Y ?
So let's create a formula in column AA:
1) identify when value in Col A matches col N, and value in col Y < 318
=and(A1=N1,Y1<318)
2) copy AA1 to all the rows of your data.
3) now we have a condition to work off .. since there is a SUMIF and COUNTIF, but no MINIF .. we'll have to build that ourselves. first the IF:
in column AB1:
=if(AA1,M1,"")
copy that down to all your data.
finally, do your min:
=MIN(AB:AB)
Should give you your answer.
You could probably splice the first two together, but again, building a complex formula like this, build it simply, first, ;)

Resources