How can I get the summation of all the cells in column B given the value in column A. Let's say I want to get the summation of all the values in column B for value "1000" in column A.
Is this possible? What I've tried so far is using SUM, INDEX, and MATCH functions but I'm only able to get the first cell data.
SUM(INDEX(A1:B8, MATCH("1000",A1:A8, 0), 2))
Anyone who has some hints for me? Thanks!
One should use SUMIFS (or its cousin SUMIF, which is slightly inferior):
=SUMIFS(B:B, A:A, 1000)
It's pretty simple:
For 1000: =SUMIF(A1:A8, "=1000", B1:B8)
For 2000: =SUMIF(A1:A8, "=2000", B1:B8)
That results in:
82.3
399.39
Related
I am trying to do a summation of rows with certain dynamic conditions. I have rows like:
A can be only one value, K can have multiple OR-values. In the end M is to be summed.
I have tried to use SUMPRODUCT() which works for column A but not for K. What I am looking for is something like:
=SUMPRODUCT(--(!$A$2:$A$20000="AA")*--(!$K$2:$K$20000="AA" OR "BB")*$M$2:$M$20000)
I know I can do ="AA" and then ="BB" but I need "AA" and "BB" to be dynamic based on other cells. And the number of arguments is different. I tried {"AA";"BB"} but I know this will not work as the match then needs to be in the same row.
Can it at all be achieved?
Thanks a lot!
=SUMPRODUCT(($A$2:$A$20000="AA")*(($K$2:$K$20000="AA")+($K$2:$K$20000="BB"))*$M$2:$M$20000)
Note that:
Since you are multiplying/adding arrays, there's no need to include the double unary's
I don't know why you have a ! in your example formula.
To return an OR array of TRUE;FALSE, we add.
Your comments still do not provide a clear explanation of what you are making dynamic.
But to create a dynamic OR for column K, including testing for column A and summing column M, you can do the following:
For column K, let us assume that your possible OR's are entered separately in the range F2:F10
=SUMPRODUCT(MMULT(--($K$2:$K$20000=TRANSPOSE($F$2:$F$10)),--(ROW($F$2:$F$10)>0))*($A$2:$A$20000="AAA")*$M$2:$M$20000)
The matrix multiplication will produce a single column of 19,999 entries which will be a 1 for matches of any of the OR's and 0 if it does not match.
See How to do a row-wise sum in an array formula in Excel?
for information about the MMULT function in this application.
In the above formula, "blanks" in the OR range (F2:F10) will also match blank entries in column K. So it is conceivable that if there is a blank in K and F and a AAA in col A and a value in column M that a wrong result might be returned.
To avoid that possibility, we can use a dynamic formula to size column F where we are entering our OR values:
=INDEX($F$2:$F$10,1):INDEX($F$2:$F$10,COUNTA($F$2:$F$10))
will return only the values in col F that are not blank (assuming no blanks within the column)
So:
=SUMPRODUCT(MMULT(--($K$2:$K$20000=TRANSPOSE(INDEX($F$2:$F$10,1):INDEX($F$2:$F$10,COUNTA($F$2:$F$10)))),--(ROW(INDEX($F$2:$F$10,1):INDEX($F$2:$F$10,COUNTA($F$2:$F$10)))>0))*($A$2:$A$20000="AAA")*$M$2:$M$20000)
Given this data:
the last formula will return a value of 5 (sum of M2,M3,M7)
Use SUMIFS with SUMPRODUCT wrapper:
=SUMPRODUCT(SUMIFS($M$2:$M$20000,$A$2:$A$20000,"AA",$K$2:$K$20000,{"AA","BB"}))
I am trying to create a VLOOKUP with condition to fill up columns G and H.
The algorithm/condition is something like this.
Target: Lookup M value from Column C, by matching the Node.
If Mz < 0, it goes to G (Take the Mininum value of Mz, i.e. largest negative Mz)
If Mz > 0, it goes to H (Take the Maximum value of Mz, i.e. largest positive Mz)
I tried to create an array formula {=IF(MIN(VLOOKUP(F2,$B:$C,2,FALSE))<0,VLOOKUP(F2,$B:$C,2,FALSE),0)}
But it doesn't seem to work properly.
Appreciate your enlightenment for this newbie. Thank you so much.
For your version of Excel:
Negatives: =AGGREGATE(15,6,1/($F2=$B:$B)*$C:$C,1)
Positives: =AGGREGATE(14,6,1/($F2=$B:$B)*$C:$C,1)
This solves the issue:
How it works:
An array (CSE) formula in cell D96:
{=MIN(IF($A$96:$A$112=$C96,$B$96:$B$112))}
An array (CSE) formula in cell E96:
{=MAX(IF($A$96:$A$112=$C96,$B$96:$B$112))}
N.B.
Finish formula with Ctrl+Shift+Enter & fill down.
Used groups are 1 to 5, you may include more.
Adjust cell references in the formula as needed.
Another solution should be Pivot Table to Find Max/Min Value In A Group.
I am trying to use the VLOOKUP function in excel to return a formula. I've found plenty here on SO about using VLOOKUP but have a slightly different question.
I am trying to get the week's average temperature (from column B) before a specified day (in column C) that can be found in column A.
Put more simply:
If date in cell C2 exists in column A, return average from range in column B.
So far this is the closest I've got (thanks to other QAs on SO):
=VLOOKUP(C2, A1:B660, AVERAGE(B124:B130), FALSE)
However using the AVERAGE function in place of column number (which would usually be the argument used) does not seem to work.
I've attached a very simplified picture of my data:
If VLOOKUP is the wrong function to handle this what would be a better approach?
I'm running Excel 15.32 on a Mac.
EDIT:
Dummy data:
https://www.dropbox.com/s/rblk943k2zf71tw/dummy%20data.xlsx?dl=0
What about:
=AVERAGE(OFFSET($B:$B,MATCH($C2,$A:$A,0)-1,0,-7))
This assumes a header in row 1.
Find the matched date in column A from the entry in C2
Create an array of column B values, counting back a week from that point
Average that array.
You can fill this down column D, for example, and it will adjust as necessary.
One problem with the OFFSET function is that it is volatile, so all the formulas would recalculate if anything is changed on the worksheet.
The following, at least in later versions of Excel, should be non-volatile:
=AVERAGE((INDEX($A:$B,MATCH($C2,$A:$A)-6,2,1):INDEX($A:$B,MATCH($C2,$A:$A,0),2)))
I will leave it to you to handle the errors from checking dates in rows 2-6.
Use INDEX as a cell reference with MATCH locating the primary date and using that position as well as that position minus 6 for the range.
=AVERAGE(INDEX(B:B, MATCH(C2, A:A, 0)-6):INDEX(B:B, MATCH(C2, A:A, 0)))
I think what you are looking for is this:
=IF(COUNTIF(A1:A660,C2)=0,0,AVERAGE(B124:B130))
This says if C2 cannot be found in A1:B660, then return 0, otherwise return the AVERAGE(B124:B130).
I would recommend a different approach. Still using VLOOKUP, I would go with the below. However there will be an easier/more elegant way to get this done.
Use VLOOKUP to return a value if found. Really, you don't care about the value it returns.
=VLOOKUP(C2,A:B,2,FALSE)
Wrap in an IFNA to handle dates not found. Here I've got it to return -1.
=IFNA(VLOOKUP(C2,A:B,2,FALSE),-1)
Use an IF statement to work out an average if VLOOKUP returns something, and do something else if it's not found.
=IF(IFNA(VLOOKUP(C2,A:B,2,FALSE),-1)<>-1,AVERAGE(B124:B130),"do something else")
How can I find the minimum value in columns B:C in the table below if the volume is <= 10.
The expected result is in yellow.
Regards,
Elio Fernandes
Either:
=AGGREGATE(15,6,C2:C9/(A2:B9<=10),1)
or, array formula**:
=MIN(IF(A2:B9<=10,C2:C9))
If there may be blank cells in B2:C9:
=AGGREGATE(15,6,1/(1/C2:C9)/(A2:B9<=10),1)
or:
=MIN(IF(A2:B9<=10,IF(ISNUMBER(C2:C9),C2:C9)))
Regards
You can use this formula to get the minimum value (Which according to me should be 20 in your data set)
=MIN(1/AGGREGATE(14,6,1/((A2:A9<=10)*B2:B9),1),1/AGGREGATE(14,6,1/((A2:A9<=10)*C2:C9),1))
for each additional column(say D) you will have to add the formula 1/AGGREGATE(14,6,1/((A2:A9<=10)*D2:D9),1) inside the MIN() formula.
Looking for a better way to do this.
EDIT:
Alternatively you could add a new row below your data. for each column you add the below formula to get the min for that column
=1/AGGREGATE(14,6,1/(($A$2:$A$9<=10)*B2:B9),1)
Now you can drag this formula to as many columns you want. Take the MIN() of this row to get the overall minimum.
I have 2 columns in my spreadsheet, both contains some numbers, column A has list of all numbers, and column B has some of the numbers from column A, now i want to highlight those numbers in column A, which are in column B here's my scenario:
Column A Column B
20301316 20322063
20302140 20322451
20307329 20326125
20307557 20334858
20314386 20371898
20314840 30368489
20322451 30384472
20326125 30384510
20334858 30384531
20371898 30384661
Here
20322451
20326125
20334858
20371898
should get highlighted. i used vlookup for this but for some reason it's highlighting all the numbers, here's the formula i used inside Conditional Formatting: (considering column A has values between A1:A10 and B has B1:B10)
=NOT(ISNA(VLOOKUP(B1, A1:B10, 1, 0)))
Could anyone please help me with proper formula.
Vlookup returns a value. In this context it is not the best formula to use, especially if you use it to return the value that you are looking up.
MATCH() is a much better fit for this scenario.
=MATCH(A1,$B$1:$B$10,0)
No fuffing around with ISNA() or wrapping in NOT() required. If it's a match it returns a number and will get formatted. If it's not a match, it won't get formatted.
It looks like you got the formula a bit backwards as it's looking in column A for values from column B. Try this instead:
=NOT(ISNA(VLOOKUP(A1,$B$1:$B$10,1,FALSE)))
Also, note that I made the lookup range an absolute reference by adding dollar signs.
Really though, I'd prefer a COUNTIF formula for this, just because I think it's more obvious:
=COUNTIF($B$1:$B$10,A1)>0