Excel lookup with two input values - excel

I have a database of multiple tables and am trying to design an equation in Excel that will return the height of a given toy from a specific manufacturer. What is the best way to go about using two inputs? i have tried working with VLOOKUP() but was unable to tailor it to my needs. I also tried nested IF statements which greatly complicated my equation and will only work with small amounts of data. Is this possible to do in Excel and if so how? The equation in the image below has dropdown selectors which aren't displayed here.

The answer that I'm giving here will require that you rearrange your data tables a little bit, but has the benefit that it can be easily extended later on to deal with any additional data and additional lookup conditions.
Steps:
Move all your data tables into one single contiguous table, and add one additional column for 'Toy type' (as shown below).
Enter the formula as shown below into a cell, but without the outer braces. Then then press Ctrl+Shift+Enter (this tells Excel that the formula is an array formula and results in the braces being added).
The lookup formula in this case is made up from an INDEX and MATCH function. This combination allows you to define multiple lookup-criteria. How this works exactly is explained in more detail here and here.

Well it looks like you've got two lookup tables... So depending on the Toy Type cell, you'd lookup vlookup area1 or area2.
See here
Results
Formula
You might like to make cell B8 a drop down list too if you were to use my layout in Excel rather than Googledocs. See my answer here

You can do a lookup based on the Toy Type to choose the range for your other lookups.
I made a table with ToyType and CellRange. Assuming your Dolls table started at B2 you would have ToyType = Dolls and CellRange = C3:D9 etc.
Then make a lookup using =VLOOKUP(SelectedToyType, NewTableRange, CellRangeColumn, FALSE)
Finally in your Toy Height lookup it would be =VLOOKUP(SelectedToyHeight, INDIRECT(FirstLookup),2,FALSE)
This will let you keep the same basic table structure, and be able to add more toy types / adjust the lookup ranges in the future.

Related

How can I multiply lookup values from two different tables and then sum them in just one cell?

I am trying to get a dedicated material table in excel. So we have a few products and these products require particular materials. I know how much and which materials go in particular products. I also know how much is sold in which year, now I want to calculate the required materials for these years. Because the productbase is large (>100), and thus >100 columns, I would like to use some lookup or index function to automate the multiplication.
As shown in the picture, I tried using a sumproduct, which was also explained in some other question on stackoverflow. This sumproduct should multiply all values obtained in one table with the corresponding values in the other. I feel that something is not right about my first two match functions (see picture again)
The code used:
=SUMPRODUCT(INDEX($B$19:$E$22;MATCH(B$2;$A$19:$A$22;0);MATCH(B$10;$B$18:$E$18;0));INDEX($B$3:$E$5;MATCH($A11;$A$3:$A$5;0);MATCH(TRUE;$B$3:$E$5>0;0)))
The image contains some extra info and explanation of the actual need
The reason that it needs a lookup or index is because the products in table 3 are always in another order than what is shown in table 1.
I would like to have this sumproduct as automated as possible, thank you in advance:)
You could try and adapt the below:
Formula in B11:
=SUM(INDEX($B:$B,MATCH($A11,$A$1:$A$5,0)):INDEX($E:$E,MATCH($A11,$A$1:$A$5,0))*TRANSPOSE(B$19:B$22))
Entered as array, CtrlShiftEnter
Drag right and down into matrix.
Side-note: Be sure to edit your question to include all relevant information, including your own atempted formula, as text. Way easier to copy paste sample data that has been formatted as markdown :)

Indirect reference to thisRow in Excel table

The situation: I have an automatic procedure for gathering data from different input-sheets and presenting in a pivot-friendly format. It appears others are in need of the same data, though they want it formatted slightly differently (and they are not friends with excel). I therefor have a version of my table formatted as they want it (with empty columns where my extract does not contain any data).
The table (both) is one line for each department for each year for each cost/income (from now, cost) category. The raw data contains the cost for each year, though some of the users want it to be cost delta from initial year. I want:
One column for raw cost (X). One column for delta cost (Y). One output column (Z) that contains one of those two values, depending on dropdown selection. The first two columns are situated to the right of the "select with mouse and copy these"-columns, so that I dont need to teach the other users how to select non-adjecent columns :P (just letting u know the level of understanding i have to work with here)
Now the naive approach to this would be to have an if-statement in column Z like this:
=IF(selected_Calc="Use raw cost";[#[X]];[#[Y]])
Alternatively nest more ifs (one for "Use difference to 2019", and potentially add more nesting if more ways to show the value should appear in future)
This works. However, it isnt as elegant as I would like it, and if I indeed end up with more ways to calculate this for other people, it will be a lot of nested ifs.
I was therefore considering something like this:
=INDIRECT("[#["INDEX(mapTab_out;match(selected_Calc;mapTab_in;0))&]]")
But this gives a #ref, and tbh i didn't really expect it to work.
The idea is though: .
Have a range mapTab_in. This has the different selections for the dropdown box.
Have the adjecent range mapTab_out. This has the name of the column (X,Y...) that contains the desired calculation)
Have in column Z a formula for selecting which column's (X,Y...) value is to be displayed in Z
The google-stuff I have found so far all seem interested in using the indirect function from outside the table, and usually want to sum an entire column. I have used this in the past. The "ThisRow" things like using # dont seem to work with indirect though. Any ideas, or have I simply made some beginner-error in my formula?
Assuming it's in the same table, you can take advantage of implicit intersection and simply use:
=INDEX(Tablename,,MATCH(selected_Calc,Tablename[#Headers],0))
where selected_Calc is the name of the column you want back. (You could make that the result of a further INDEX/MATCH if you want to use a lookup table for some reason.)

$ (dollar sign) equivalent for structured notation (Excel Worksheet table)

I'm basically looking for a $A:$A equivalent for structured table references in Excel.
Say I have this formula:
=INDEX(tChoice,MATCH(OFFSET(tData[#[cm_sex]],-3,0),tChoice[name],0),3)
Basically tData is a table full of raw data (many columns), taken from surveys (so each column is Survey question, more or less). tChoice is a smaller table (just a few columns), I basically want to look up into tChoice the raw data value & return a label based on that (to value-label table is tChoice).
I actually want the tData[#[cm_sex]] to auto-increment as I apply formulas in cells to the left (so I cycle through all the columns of the raw data), however I DON'T want the column tChoice[name] to change: e.g. the column to look for a match based on the raw table data.
This is equivalent to writing, say, A:A (which would auto-increment to B:B, C:C, etc) and $A:$A (which would not).
Is there a dollar sign equivalent for structured table references?
P-S: Of course I can other things like increment the whole thing, than search & replace the range with say tChoice[*] replaced by tChoice[name]... However it would be cleaner & more efficient to have a proper notation for it....
Didn't find it in the support pages (https://support.office.com/en-us/article/Using-structured-references-with-Excel-tables-f5ed2452-2337-4f71-bed3-c8ae6d2b276e)
user3964075 provided the answer in the comments. I had never seen this before so thanks to him or her for this answer. There's some information out there on the web about absolute structured table references, so I thought I'd summarize what I found.
For your situation you can use tChoice[[name]:[name]] Specifying a range that's just the one column anchors the column like $ signs do in normal cell references.
If you want to just deal with one row (the one that the formula is in) the anchor looks like this:tChoice[#[name]:[name]].
Now say you want to anchor one cell but have the other be relative, as in this scenario where I'm summing from a to the right, starting with a:a, then a:b, etc:
You can do that with a formula like this, where the first part is absolute and the second is relative:
=SUM(Table1[#[a]:[a]]:Table1[#a])
Note that these formulas much be dragged, not copied. Perhaps there is a keyboard shortcut that does this.
This process is rather clunky compared to just clicking F4, as with a regular cell reference. Jon Acampora has created an addin that automates this process, as well as two detailed posts on this topic. His first post contains a link to the one with the addin.

Whole Column Formula Efficiency for MS Excel Built in Functions

I've been trying to find a list of the built in MS Excel functions that calculate "Whole Column" formula efficiently but haven't been successful, any ideas where I can go for this information? What i mean by this is exemplified below:
This documentation suggests that SUM and SUMIF formula automatically pick up on the last row of data, thus meaning that there is no efficiency reason why using a more restricted or dynamic range is preferable.
https://msdn.microsoft.com/en-us/library/office/ff726673(v=office.14).aspx#xlAllowExtraData
Answers for Excel 2003/7/10 are all welcome.
I think it would be fair to assume that ALL excel functions behave as teh article describes (ie the same as SUM and SUMIF). (I wasn't aware of this article, but it makes sense when you think about it...)
Behind the scenes the data in cells is stored in OO data structures such that only cells with non-default values and formatting will have been created.
It's highly probable that the value data and formatting data are help in separate containers.
So when Excel is using a formula on a range it is working on the data structures and consequently only works with the cells that have values.
I hope that a whole column with cells having different formatting (but very values) does not cause the SUM and SUMIF formulas to scan through every cell.
If in doubt you could do an experiment with the formulas you want to use.
The link you gave talked about formulas that behave differently and explicitly named VBA user created functions and array formulas - which makes sense.
Also, note that the article says using "Structured Table References" is the best approach. (ie not only storing your data in ranges but storing your data in excel tables. Created from a range using Ribbon:INSERT>Table).
These tables will allow any function to be used more efficiently as the range used is limited to the number of rows the table has.
I hope this helps.
Harvey

Excel Index Match - Partial strings with Multiple Results

I'm trying to tweak this piece of code I found in a sample spreadsheet online but I can't quite get my head around it.
The original spreadsheet basically does an INDEX/MATCH based on a user-defined lookup and lists the matches neatly in a concatenated list. The sample spreadsheet's output looks like this:
http://i.stack.imgur.com/DyahB.png - Sample Excel Output (Note how there are no gaps between the first and second matches)
The underlying algorithm is:
=IF(ISERROR(INDEX($A$1:$B$8,SMALL(IF($A$1:$A$8=$E$1,ROW($A$1:$A$8)),ROW(1:1)),2)),"",INDEX($A$1:$B$8,SMALL(IF($A$1:$A$8=$E$1,ROW($A$1:$A$8)),ROW(1:1)),2))
Now, I want the lookup to instead retrieve PARTIAL matches, and in addition, generate the outputs horizontally like so:
http://i.stack.imgur.com/ShED0.png - Output is generated horizontally based on partial matches
I'm not sure how I would go about doing this. It seems like I would somehow try and change the IF condition to return true on partial matches but I can't get my head around it. Please help!
Assuming by "partial match" you mean text that starts with the value in L1 then use this formula in N1
=IFERROR(INDEX($I$2:$I$8,SMALL(IF(LEFT($H$2:$H$8,LEN($L$1))=$L$1,ROW($I$2:$I$8)-ROW($I$2)+1),COLUMNS($N1:N1))),"")
confirm with CTRL+SHIFT+ENTER
and copy across
For a match anywhere in the text you can use this version
=IFERROR(INDEX($I$2:$I$8,SMALL(IF(ISNUMBER(SEARCH($L$1,$H$2:$H$8)),ROW($I$2:$I$8)-ROW($I$2)+1),COLUMNS($N1:N1))),"")
Neither formula is case-sensitive, although you can easily make the latter so by changing SEARCH to FIND
Use of IFERROR function means you don't need repetition for error handling - needs Excel 2007 or later version
Building on Barry's code a little, I needed to make a few tweaks for my own use (current project I have at work).
Tweaks I made:
Returning the cell that matches my search criteria in my index
Making the cell draggable in two dimensions so I could index multiple columns for specific information
Making the "nth" counter vertical instead of horizontal (as my application is a database of sorts, and each column is a separate entry. At the top of each column is 5 rows populated based on the search term [in my case, the store number])
The final result is:
=IFERROR(INDEX(A$8:A$295,SMALL(IF(ISNUMBER(SEARCH('Store History'!$F$2,A$8:A$295)),ROW(A$8:A$295)-ROW(A$8)+1),ROWS(A$2:A2))),"")
It is worth repeating that this is an array formula and needs to be entered using CTRL+SHIFT+ENTER
This is placed in cell A2 and is dragged both vertically and horizontally (horizontally in my case is ever expanding as I add more entries into my database).
My purpose for adding this comment (even though it is a long inactive thread) is to try and make this a more relevant search result on Google for "excel index match partial strings with multiple results" or variations of that. It took me hours of searching to find this solution, and it is extremely functional and elegant. My thanks to the OP and especially to Barry for his code!!

Resources