I need a formula to:
Lookup in its own column for the largest #
only if conditions are met in column 1 and 2
Add 1 to the found number and insert it into the cell
In other words, I want to "filter" my list for rows that have X in column 1 and Y in column 2
and then get the largest number from column 3 within these rows.
Then add 1 to that number.
This can be achieved with a array formula:
{=MAX(IF(($A$1:$A$1000="x")*($B$1:$B$1000="y"),$C$1:$C$1000))+1}
Input:
=MAX(IF(($A$1:$A$1000="x")*($B$1:$B$1000="y"),$C$1:$C$1000))+1
and then [Ctrl]+[Shift]+[Enter] to create a array formula.
Then should there be automatically the curly brackets around the formula.
Greetings
Axel
Standard (non-array) equivalent for MAXIF() functionality would look like:
=MAX(INDEX(C2:C999*(A2:A999="X")*(B2:B999="Y"),,))+1
With your added condition for adding 100 to numbers less than 100 then,
=MAX(INDEX((C2:C999+(C2:C999<100)*100)*(A2:A999="X")*(B2:B999="Y"),,))+1
For versions of Excel that are 2010 and higher, the AGGREGATE¹ function can use the conditional criteria to throw errors then ignore the errors when processing the MAX function.
The standard formulas for E5:E6 are,
=AGGREGATE(14, 6, $C$2:$C$99/(($A$2:$A$99="X")*($B$2:$B$99="Y")), 1)
=AGGREGATE(14, 6, ($C$2:$C$99+($C$2:$C$99<100)*100)/(($A$2:$A$99="X")*($B$2:$B$99="Y")), 1)
In fact, AGGREGATE is using its LARGE sub-function with 1 as the k parameter. Locating the second, third, etc. largest values which meet the criteria is a simple matter of sequencing the k parameter. This can be done with ROW(1:1) then filling the formula down.
¹AGGREGATE¹ was introduced in Excel 2010. It is not available in previous versions.
Related
I have two columns of data:
A has names in rows 1-5 (Amy, Greg, Matt, Sean, Greg).
B has numbers in rows 1-5 (90, 20, 30, 40, 50).
I want to write an excel function that will give me the number of the row with the name Greg in column A where the number in column B is greater than 25.
I have tried two functions that are not working:
=MATCH("Greg"&TRUE,A1:A6&B1:B6>25,0)
=Match("Greg"&>25,A1:A6&B1:B6,0)
I am pressing ctrl + shift + enter to do an array and it is still not working.
I am unable to sort the values (due to other constraints) so I cannot use the final argument in the match function to achieve the >25 argument.
Try a standard formula AGGREGATE instead of an array formula MATCH.
=aggregate(15, 7, row(a:a)/((a$1:a$6="greg")*(b$1:b$6>25)), 1)
To get possible second, third, etc. matching row numbers, change the 1 at the end to row(1:1) and fill down.
While I don't typically use this style of array formula, your original would have worked as a CSE formula if changed to this,
=MATCH("Greg"&TRUE, A1:A6&(B1:B6>25), 0)
I would like excel to display the value from table array which has two matching cells com_cd and div_cd using INDEX and MATCH.
I have tried the following formula but it did not work.
=INDEX(K9:K53,MATCH(K3,I9:I53,0),MATCH(K4,J9:J53,0))
Here is a screenshot of the excel sheet with the desired result given according to com_cd and div_cd
Try an array formula (CTRL + SHIFT + ENTER) instead of Enter.
=INDEX(K9:K53,MATCH(K3&K4,I9:I53&J9:J53,0),1)
Not tested but should work.
Will edit later explaining our formula and reason why your formula doesn't work.
Your column_num parameter on the INDEX function cannot sinply provide a secondary row criteria. You need a way to ensure a two column match on the row_num parameter and leave the column_num either blank or as 1 (there is only only column in K9:K53).
The standard formula for K5 should be,
=index(K9:K53, aggregate(15, 6, row(1:45)/((i9:i53=k3)*(j9:j53=k4)), 1))
... or,
=index(K9:K53, min(index(row(1:45)+((i9:i53<>k3)+(j9:j53<>k4))*1e99, , )))
The cell range K9:K53 has a total of 45 rows. The position within K9:K53 will be within ROW(1:45). The first formula forces any non-matching row into an #DIV/0! error state and the AGGREGATE¹ function uses option 6 to ignore errors while retrieving the smallest valid entry with the SMALL sub-function (e.g. 15). The second formula performs the same action by adding 1E+99 (a 1 followed by 99 zeroes) to any non-matching row and taking the smallest matching row with the MIN function.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.
I am analysing library statistics relating to loans made by particular user categories. The loan data forms the named range LoansToApril2013. Excel 2007 is quite happy for me to use an index range as the sum range in a SUMIF:
=SUMIF(INDEX(LoansToApril2013,0,3),10,INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
Here 10 indicates a specific user category, and this sums loans made to that group from three columns. By "index range" I'm referring to the
INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6)
sum_range value.
However, if I switch to using a SUMIFS to add further criteria, Excel returns a #VALUE error if an index range is used. It will only accept a single index.
=SUMIFS(INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
works fine
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
returns #value, and I'm not sure why.
Interestingly,
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
is also accepted and returns the same as the first one with a single index.
I haven't been able to find any documentation or comments relating to this. Does anyone know if there is an alternative structure that would allow SUMIFS to conditionally sum index values from three columns? I'd rather not use three separate formulae and add them together, though it's possible.
The sumifs formula is modelled after an array formula and comparisons in the sumifs need to be the same size, the last one mimics a single column in the LoansToApril2013 array column 4:4 is column 4.
The second to bottom one is 3 columns wide and the comparison columns are 1 column wide causing the error.
sumifs can't do that, but sumproduct can
Example:
X 1 1 1
Y 2 2 2
Z 3 3 3
starting in A1
the formula =SUMPRODUCT((A1:A3="X")*B1:D3) gives the answer 3, and altering the value X in the formula to Y or Z changes the returned value to the appropriate sum of the lines.
Note that this will not work if you have text in the area - it will return #VALUE!
If you can't avoid the text, then you need an array formula. Using the same example, the formula would be =SUM(IF(A1:A3="X",B1:D3)), and to enter it as an array formula, you need to use CTRL+SHIFT+ENTER to enter the formula - you should notice that excel puts { } around the formula. It treats any text as zero, so it will successfully add up the numbers it finds even if you have text in one of the boxes (e.g. change one of the 1's in the example to be blah and the total will be 2 - the formula will add the two remaining 1s in the line)
The two answers above and a bit of searching allowed me to find a formula that worked. I'll put it here for posterity, because questions with no final outcome are a pain for future readers.
=SUMPRODUCT( (INDEX(LoansToApril2013,0,3)=C4) * (INDEX(LoansToApril2013,0,1)="PTFBL") * INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
This totals up values in columns 4-6 of the LoansToApril2013 range, where the value in column 3 equals the value in C4 (a.k.a. "the cell to the left of this one with the formula") AND the value in column 1 is "PTFBL".
Despite appearances, it isn't multiplying anything by anything else. I found an explanation on this page, but basically the asterisks are adding criteria to the function. Note that criteria are enclosed in their own brackets, while the range isn't.
If you want to use names ranges you need to use INDIRECT for the Index commands.
I used that formula to check for conditions in two columns, and then SUM the results in a table which has 12 columns for the months (the column is chosen by a helper cell which is 1 to 12 [L4]).
So you can do if:
Dept (1 column name range [C6]) = Sales [D6];
Region (1 column name range [C3]) = USA [D3];
SUM figures in the 12 column monthly named range table [E7] for that 1 single month [L4] for those people/products/line item
Just copy the formula across your report page which has columns 1-12 for the months and you get a monthly summary report with 2 conditions.
=SUMPRODUCT( (INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7),0,L$4))
Part 1:
I was able to construct a formula that does exactly what I want (from some examples), but yet, I'm unable to figure out how exactly it works. I have, starting with cell A1:
Price $
table 20
chair 10
Invoice Quantity
table 17
chair 1
chair 2
table 3
What I want is the final total (430) for the invoice which is computed as Quantity*Price for each item (17*20 + 1*10 + 2*10 + 3*20). the following formula correctly does this:
=SUMPRODUCT(B6:B9,SUMIF(A2:A3,A6:A9,B2:B3))
I understand the basics of SUMPRODUCT and SUMIF. But here, my argument for SUMIF's range is A2:A3, which makes me think the SUMIF would iterate through A2 and A3, and not through A8:A11 (which is the criteria). What gives?
Edit: the unclear part is, what exactly does SUMIF do (what is its iteration pattern) when the first two arguments are of different dimensions (here, the range is 2 cells while the criteria is 4 cells). Also, what is the "output" of SUMIF? An array? Of what dimensions?
Part 2:
In addition, if I ignored the quantity and simply wanted to add 20 whenever I saw a table and 10 whenever I saw a chair, I figured I would do:
=SUMIF(A2:A3,A6:A9,B2:B3)
But that doesn't work, and I have to enclose it with a SUMPRODUCT() for it to work and correctly evaluate to 60. Enclosing it within a SUM doesn't work either (probably because the SUMIF doesn't return an array?) Why?
I've read a bunch of tutorials and still can't understand this, and would be most grateful for a clear, intuitive explanation for both these cases. Thank you.
SUMIF can produce an array of results. If you take my formula
=SUMIF(A6:A9,A2:A3,B6:B9)
it says
For the criteria in A2 (ie table)
- look at A6:A9
- where table is matched, sum the corresponding value in B6:B9
- returns 20 (ie 17 +0 +0 +3)
- this is stored in the first position of the array
Then for the criteria in A3 (ie chair)
- look at A6:A9
- where table is matched, sum the corresponding value in B6:B9
- returns 3 (ie 0 +1 +2 +0)
- this is stored in the second position of the array
So the end array from the SUMIF is {20:3}
You can see the array result by highlighting the SUMIF formula in Excel's formula bar and then pressing F9
Then use SUMPRODUCT to multiple the count in the SUMIF by the $ values in B2:B3 to get total dollars
={20;3}*{20:10}
=20*20 + 3*10
= 430
Part 1
Rather than
SUMIF(A2:A3,A6:A9,B2:B3)
which produces a four element array of
={20;10;10;20}
(corresponding to table;chair;chair;table)
You should use
SUMIF(A6:A9,A2:A3,B6:B9)
which sums the values in B6:B9 against your two criteria in A2:A3 giving the desired result
={20;3}
(corresponding to table;chair)
and then use SUMPRODUCT to weight your array, ie
=SUMPRODUCT(SUMIF(A6:A9,A2:A3,B6:B9),B2:B3)
={20;3}*{20:10}
=430
Part 2
Use COUNTIF to return an array of the number of chairs and tables and then multiply by the vales using SUMPRODUCT
=SUMPRODUCT(B2:B3,COUNTIF(A6:A9,A2:A3))
={20;10} * {2;2}
=60
Well you only have one minor mistake:
probably because the SUMIF doesn't return an array?
SUMIF can work with arrays, thats why you formula SUMPRODUCT( SUMIF() ) works in first place, to SUMIF show an array you have to select a group of cells (like C6:C9) input the formula and use CTRL+SHIFT+ENTER instead of ENTER only. this generate an "array fomula", identified by curly brackets {} (those can only be entered with CTRL+SHIFT+ENTER, no manualy) and show the array formula and results
I am using excel 2002 to create a spreadsheet. What I am trying to do is use the countif function but I have more than one condition. So I have 2 columns with a list of numbers and what I want to say is count the number of occurences where the number x is in one column and the number y is in the other column (in the same row).
E.g.
1 1
1 1
1 2
2 2
2 3
3 3
So if in the above I wanted to count the rows where the first column had the number 1 and the second column had the number 2, the answer should be 1.
I can't use the COUNTIF function because that only allows you to specify one condition and the COUNTIFS isn't available because I am using excel 2002.
Please Help.
This is a job for an array formula. In your case you can do:
=SUM((A1:A6=1)*(B1:B6=2))
entered as an array forumla (Ctrl-Shift-Enter)
The equality tests each return an array of boolean values, and the multiplication does an element-wise multiply (so a logical AND in this case). SUM coerces booleans to numbers when it adds up the resulting array.
EDIT:
In an answer to this similar question:
https://stackoverflow.com/questions/576569/use-2-conditions-in-excel-sumif
Jon Fournier posted a link to:
http://www.cpearson.com/excel/ArrayFormulas.aspx
which has a lot more detail on this sort of thing.
You could create a 3rd column which joins the two other column values with (say) a space or other special character, and then test for the combined value with COUNTIF.
If you don't want to add another column on your worksheet, you could put it on a different worksheet - or even create a dynamic named range.
Personally I love the SUMPRODUCT function but I'm not sure if you have it in Excel2002
Here's a very good resource for multiple conditions:
http://www.ozgrid.com/Excel/sum-if.htm
The DCOUNT function allows for multiple criteria.
The formula would look like this
=DCOUNT(A2:B8,"ColumnA",A11:B12)
if you have your criteria below the data.
Screenshot of data and formula http://img31.imageshack.us/img31/1093/dcount.png