I'd like to create a table lookup formula that matches two columns. For instance, suppose I'd like to find the value of the Letter column at the row where the Type column is Biennial and the Result column is Warning.
A B C
1 Letter Type Result
2 A Annual Exceeds
3 B Biennial Warning
4 C Biennial DevelopmentNeeded
5 D Biennial PartiallyMeets
6 E Annual Meets
What would the formula look like to accomplish this?
The SUMPRODUCT() formula is really apt for situations where you want to lookup a value with multiple criteria. It is most convenient when wanting to look up numeric values, but it can be adjusted to look up string values as well. As a bonus, you can avoid having to use array formulas.
This particular problem can be tackled with the following formula (indentation added for legibility, which you can do in Excel formulas using ALT + ENTER):
=INDEX(
$A$2:$A$6,
SUMPRODUCT(
($B$2:$B$6 = "Biennial") *
($C$2:$C$6 = "Warning") *
ROW($A$2:$A$6)
) - 1
)
First, SUMPRODUCT() is used to filter out the proper rows using ($B$2:$B$6 = "Biennial") and ($C$2:$C$6 = "Warning"); the multiplication operator * functions as an AND operator (the + operator would function as an OR operator).
Then the result is multiplied by ROW($A$2:$A$6) to find the particular row that has the combination. SUMPRODUCT() then adds everything up, which in this case gives us 3. As the result sought is actually on row 2 due to the column headings, we subtract 1. By applying the INDEX() function, we get the desired result: B.
Beware though that this is the case if and only if the combination sought is unique. If the combination sought exists more than once, this will break down.
Another method that avoids array entry is:
=INDEX($A$2:$A$6,MATCH(2,index(1/(($B$2:$B$6="Biennial")*($C$2:$C$6="Warning")),0)))
It exploits the fact that the match function ignores certain errors and that index manages arrays naturally.
You can use an array formula if you like:
=INDEX($A$2:$A$6,MATCH(1,($B$2:$B$6="Biennial")*($C$2:$C$6="Warning"),0))
Enter in with Ctrl+Shift+Enter
If you want to do this without array formulas, one way you could do it is by creating a helper column.
Column D to have the formula:
=B2&C2
Copied down
Then the new formula could be:
=INDEX($A$2:$A$6,MATCH("BiennialWarning",$D$2:$D$6,0))
It's just a play on the text, really.
Related
So I have column A with mpnths. Column B has percent win and loss. I want to add 1 to the value in column B and then find the product of all values in column B to determine the compound growth of the dataset. Then I want to take this value and put in in my reports sheet.
=PRODUCT(SUM(1,IF(MONTH('#MOMO Trades'!A1:A1000)=4,'#MOMO Trades'!B:B,0)))
Please help me correct this formula.
thanks!
In order for the SUM function to add 1 to each row individually, you will need to use an array formula, rather than a formula. Otherwise, it will try to add 1 to an array, which it can't do.
To do this, enter the formula as you would normally, but when you have typed it press Ctrl+Shift+Enter instead of just Enter. It will show up surrounded by braces, like this:
{=PRODUCT(SUM(1,IF(MONTH('#MOMO Trades'!A1:A1000)=4,'#MOMO Trades'!B:B,0)))}
I have been looking around for a while but unable to find an answer to my question.
In Excel, what compact formula can I use to create an array made up of a single element repeated n times, where n is an input (potentially hard-coded)?
For example, something that would look like this (the formula below does not work but gives an idea of what I am looking for):
{={"Constant"}*3}
Note: I am not looking for a VBA-based solution.
EDIT Reading #AxelRichter answer, I see I should also indicate that the formulas below assume Constant is a number. If Constant is text, then this solution will not work.
Volatile:
=ROW(INDIRECT("1:" & Repts))/ROW(INDIRECT("1" & ":" & Repts)) * Constant
non-Volatile:
=ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,Repts,1))/ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,Repts,1))*Constant
If
Constant = 14
Repts = 3
then
Result = {14;14;14}
The first part of the formulas create an array of 1's repeated Repts times. Then we multiply that array by Constant to get the desired result.
And after reading #MacroMarc's comment, the following non-volatile formula shouyld also work for numbers:
=(ROW($A$1:INDEX($A:$A,Repts))>0)*Constant
One could concatenate 1:n empty cells to the "Constant" to create a string array having n items "Constant":
"Constant"&INDEX(XFD:XFD,1):INDEX(XFD:XFD,3)
There 3 is n.
Used in Formula
=INDEX("Constant"&INDEX(XFD:XFD,1):INDEX(XFD:XFD,3),0)
Evaluate Formula shows that it works:
Here column XFD is used because in most cases this column will be empty and a column which is guaranteed to be empty is needed for this solution.
If used
"Constant"&T(ROW($A$1:INDEX($A:$A,3)))
=INDEX("Constant"&T(ROW($A$1:INDEX($A:$A,3))),0)
the need of an empty column disappears. The function ROW returns numbers but the T returns an empty string if its parameter is not text. So empty strings will be concatenated for each 1:3 (n).
Thanks to #MacroMarc for the hint.
Try:
REPT("Constant", SEQUENCE(3,1,1,0))
Or, if the reference is to a dynamic array:
REPT("Constant", SEQUENCE(A1#,1,1,0))
The dynamic array spills, and has your constant repeated one time.
Using SEQUENCE with a step of 0 is a much cleaner way to make an array of constants. You can choose whether you want rows or columns (or both!) as well.
=SEQUENCE(Repts,1,Constant,0)
I will generally use a sequence (like Claire (above) said). But if you want to provide an output of text objects, I would do it this way:
=IF(SEQUENCE(A1,A2,1,0),A3)
Where:
A1 has the number of rows
A2 has the number of columns
A3 has the thing you want repeated into an array
The sequence will create a matrix of 1's, which the IF statement will default to the TRUE expression (being the contents of A3).
So, if you wanted a vertical list of 3 items that says "Constant", this would do it:
=IF(SEQUENCE(3,,1,0),"Constant")
If you would prefer it be arranged horizontally instead of vertically, just amend the SEQUENCE function:
=IF(SEQUENCE(,3,1,0),"Constant")
As you can see, I have a database table on the left. And I want to add in IF statement that allows me to lookup the [Code], [Name] and [Amount] of the top 5 of Company A ONLY. Then do a top 5 for Company B and so on. I have managed to lookup the top 5 out of ALL companies but cannot seem to add a criteria to target specific company.
Here are my formulas so far:
Formula in Column K [Company]: = INDEX(Database,MATCH(N3,sales,0),1)
Formula in Column L [Code]: = INDEX(Database,MATCH(N3,sales,0),2)
Formula in Column M [Name]: = INDEX(Database,MATCH(N3,sales,0),2)
Formula in Column N [Amount]: = LARGE(sales,ROW(1:20))
The intended result is to show the top 5 sales person in each company along with their [Code], [Name] and [Amount], feel free to suggest any edits to the worksheet.
Here's an alternative if you know the code is unique. After putting A into K3:K7
First get the highest amounts for Company A starting in N3
=AGGREGATE(14,6,Database[Amount]/(Database[Company]=K3),ROWS(N$1:N1))
Then find the code which matches the amount, but only if it hasn't been used before (this assumes that the code is unique) starting in L3
=INDEX(Database[Code],MATCH(1,INDEX((Database[Company]="A")*(Database[Amount]=N3)*ISNA(MATCH(Database[Code],L$2:L2,0)),0),0))
Then find the matching name with a normal INDEX/MATCH starting in M3
=INDEX(Database[Name],MATCH(L3,Database[Code],0))
Okay, I have achieved this with the use of a helper column which you can hide. Please nnote though that this will only work as long as there are not more than 9 identical totals for any 1 company, I don't think you should have that issue but it may occur, the digits being added by the helper column would need to be tweaked
First Helper Column:
Adds a digit to the end of the total representing the number of times that amount already exists above for that company. This formula is =CONCATENATE([#Amount],COUNTIFS($A$1:A1,A2,$D$1:D1,D2))*1
This is multiplied by 1 to keep the number format for LARGEto work with.
Second Helper Column:
This is an array formula and will need to be input by using Ctrl+Shift+Enter while still in the formula bar.
The formula for this one is:
=LARGE(IF(Company="A",Helper),ROW(1:1))
What this formula does as an array formula is produce a list of results based on the IF statement that LARGE can use. Rather than the entire column being ranked largest to smallest, we can now single out the rows that have company "A" like so:
=LARGE({20000;20001;20002;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;15000;14000;30000;FALSE;FALSE;FALSE;FALSE},ROW(1:1))
LARGE will only work with numeric values so the FALSES produced where column A does not match "A" will be ignored. Notice why I have used the helper column here to eliminate unique values but not affect the top 5.
ROW(1:1) has been used as this will automatically update when the formula is dragged down to produce the next highest result in this array.
The main formula for top 5 array
Again this is an Array formula so will need to be input by using Ctrl+Shift+Enter while still in the formula bar.
=INDEX(Database,SMALL(IF(Company="A",IF(Helper=$O3,ROW(Company))),1)-1,COLUMN(A:A))
With array formulas for some unknown reason IF(AND()) just does not work for me so I have nested two IF's instead.
Notice how I am again checking whether the first column matches "A" and then whether the last column matches the result of the second formula. What will happen is where both of these conditions match in the array (as in both produce TRUE for the same row) I wanted the row number to be returned.
IF({TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE},IF({FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE},{2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20}))
It looks like a mess I know, but the position where both TRUEs align gives us the row 16 as a result.
{FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;16;FALSE;FALSE;FALSE;FALSE}
As I know that there can only be one match possible for this, I use SMALL to grab the first smallest number to use in the INDEX formula for row and deduct 1 as we are not considering the headers in the INDEX formula so we actually want the 15th result.
Again, COLUMN(A:A) has been used for the column number to return as this will automatically update when the formula is dragged across.
If you are struggling with my explanation and want me to provide more clarity, feel free to reach out and I will try my best to explain the logic in more detail
I am trying to create an INDEX MATCH formula that searches through a column containing a list of jpegs and returns all jpegs that start with a particular string and converts them to a hyperlink.
Currently my formula returns just the first instance, but I'd like it to return all matches.
The list of jpegs is in column F (F1:F1000) on Sheet 2 of the workbook. The string that is being used in the search is the product SKU in column A, sheet 1.
Here is the working non-array version which I have entered in C2 on sheet 1 and filled down:
=IFERROR(
HYPERLINK(
CONCATENATE(sku_url,INDEX(Sheet2!$F$1:$F$1000,
MATCH(A2&"*",Sheet2!$F$1:$F$1000,0),1))),
"image not found")
This works for column C, but how can I fill this formula to the right so that column D contains the second image for each sku, E contains the third, and so forth. I plan to have no more than six images for each SKU, so I have assigned columns C through H to product image URLs. If a SKU doesn't have six images, these extra columns should be empty.
Assuming use of Excel 2010 or later:
=IF(COLUMNS($A:A)>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),"",IFERROR(HYPERLINK(CONCATENATE(sku_url,INDEX(Sheet2!$F:$F,AGGREGATE(15,6,ROW(Sheet2!$F$1:$F$1000)/(LEFT(Sheet2!$F$1:$F$1000,LEN($A2))=$A2),COLUMNS($A:A))))),"imagenotfound"))
As way of an explanation, the initial IF clause, i.e.:
IF(COLUMNS($A:A)>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""
is straightforward enough:
COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*")
simply gives a count of the total number of rows which match that condition, and since:
COLUMNS($A:A)
which is equal to 1 and becomes, when copied to the right, successively:
COLUMNS($A:B)
(which is equal to 2)
COLUMNS($A:C)
(which is equal to 3)
etc., etc., this clause will be equivalent to, in successive columns:
IF(1>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""
IF(2>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""
IF(3>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""
etc., etc., and so a blank will be returned in cells where that initial clause is TRUE.
The only other clause of note is that which generates an array of successive row numbers for when this condition is met. Unfortunately the COUNTIF statement above is, for technical reasons, not employable within our AGGREGATE construction.
Fortunately we can reproduce the results of that COUNTIF statement using another set-up with LEFT.
Reducing the range in question temporarily from F1:F1000 to F1:F10 to aid the explanation, this part:
LEFT(Sheet2!$F$1:$F$10,LEN($A2))=$A2
will simply generate an array of Boolean TRUE/FALSE returns as to the result of that statement for each of the entries in F1:F10. We might have, for example:
{FALSE;TRUE;FALSE;TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE}
When we then reciprocate the equivalent row numbers for each of those entries with this array of Booleans, i.e. perform:
ROW(Sheet2!$F$1:$F$10)/(LEFT(Sheet2!$F$1:$F$10,LEN($A2))=$A2)
we have:
{1;2;3;4;5;6;7;8;9;10}/{FALSE;TRUE;FALSE;TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE}
and since, when coerced by any suitable mathematical operation (of which division is one), Boolean TRUE/FALSE values are coerced into their numerical equivalents (TRUE=1, FALSE=0), the above becomes:
{#DIV/0!;2;#DIV/0!;4;5;#DIV/0!;7;#DIV/0!;9;#DIV/0!}
Since AGGREGATE, with a first parameter of 15 is instructed to find the smallest value within an array, and with a second parameter of 6 is instructed to ignore any error values within that array, all that is left is to set the fourth parameter within that function, k, which determines whether the first smallest, second smallest, etc. value should be returned.
Again, by using:
COLUMNS($A:A)
for this parameter, which we know will generate a series of consecutive integers (1, 2, 3, etc.) as copied to the right, we thus guarantee that we will return the required row number to each version of the formula.
Regards
Use the AGGREGATE¹ function with the SMALL sub-function (15). Adjust the k parameter to increase with COLUMN as you fill right.
The standard (non-array) formula in B2 is,
=IFERROR(
HYPERLINK(
CONCATENATE(sku_url, INDEX(Sheet2!$F:$F,
AGGREGATE(15, 6, ROW($1:$999)/(LEFT(Sheet2!$F$1:$F$999, LEN($A2))=$A2), COLUMN(A:A))))),
"image not found")
Fill right as necessary.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.
I'm trying to minimize creating uneccessary tables in Excel, and instead of creating a table to multiply columns A and B, can I do it within the IF formula? Perhaps using Array formulas?
I tried Ctrl + Shift + Enter to enter the following formula:
SUMIFS($A$1:$A$10*$B$1:$B$10,$C$1:$C$10,"Value")
however it did not work.
Basically, I want to sum the product of A & B (i.e A*B) if the value in C is equal to "value".
SumProduct is what you need
=SUMPRODUCT($A$1:$A$10,$B$1:$B$10,--($C$1:$C$10="Value"))
Entered as a standard (not array) formula
This formula checks if the value in Column C is equal to 4 in this example. If so, it returns the product, if not, it returns 0. You enter this formula in for example column D and drag it down.
=IF(C1=4;SUMPRODUCT(A1:B1);0)