My current formula is: =XLOOKUP(R2&S3,X1:EA1&X2:EA2,X1:EA150) with the source data being in the same sheet (X1:EA150). However, the source data is not usually within the same sheet (I only copied it over to see if the formula works). How do I nest(?) another =xlookup within my current formula to find the source data in Sheet1. I don't really want to use helper cells as then I'll have 2 dynamic ranges unless it can be automated.
(my previous question)
Thanks
Screenshot(s) refer:
The issue doesn't concern ranges from what I can tell - it's the missing final parameter assoc. with xlookup (like match: exact match: 0 etc.).
Of course, this assumes that your lookup ranges (K1:N1, K2:N2) correspond with respective lookup values that you have combined as (H2 & I3).
=XLOOKUP(H2&I3,K1:N1&K2:N2,K2:N11,"not found",0)
It's a trivial matter to then cut the appropriate range (i.e. contiguous range, 1:1 correspondence with resp[. (sub/) function ranges etc)
But what about duplicate match results?
The above will only return the first instance of a match. If you're looking to return every instance where there is a match, then I far prefer the filter function for this job:
=FILTER(K2:N11,--ISNUMBER(MATCH(K1:N1,H2,0)*MATCH(K2:N2,I3,0)))
And now we have this:
(assumes Office 365 compatibility RE: Excel)... ta
Related
Using Microsoft 365 Excel.
In cell K2, I have:
=VLOOKUP(F2,METERS,2,FALSE)
In cell L2:
=VLOOKUP(G2,KNOTS,2,FALSE)
The result in L2 is what I expect.
No matter what I do to the equation or anywhere in the workbook, I keep getting #N/A in K2.
When I replace the named range in K2, METERS for KNOTS, the function evaluates properly.
Copying the named range works properly, so there's nothing wrong with the named range:
=METERS
returns the complete named range without errors.
Checking the value in F2 evaluates as TRUE, so the value is an exact match:
=(F2=MS!A210)
Oddly enough, if I change the function in K2:
=VLOOKUP(F2,METERS,2,TRUE)
then it sort of works, in that it gives me a value instead of #N/A, but doesn't give me exactly the result I need.
I tried moving the function from K2 to different cell and using a different cell for the lookup value; then no matter what I input, I get 0.
I know the syntax in K2 is correct. The named range is correct. Everything seems to be correct.
Yet no matter what, I get #N/A.
Here/screenshot(s) refer:
Given the info you have provided, the only reasons I can think of why this could occur are:
a) Conflicting named ranges with common names/different scopes
b) Inconsistency between the two named ranges you're using
These aren't mutually exclusive (a different scope could lead to an inconsistency). I'll demonstrate the following in this solution:
No issues arise when using two different names that refer to the exact same range / sheet / scope
How easily issues can arise due to duality of scope (e.g. worksheet vs. workbook) for common names, and how either of these can be referenced anywhere in the workbook
Finally, I'll comment on the 'true/false' indicator in the vlookup function you mentioned, and propose an alternative / improved feature avail. with Office 365.
Context
Conflicts RE: named ranges can arise in several ways - e.g. when multiple sheets contain named ranges that have common names, when copying a function that comprises a named range from one sheet to another, etc. It's possible to produce a conflict from one workbook to another in this fashion too.
When copying such a function from one sheet to another you should see the something like the following UI appear:
Sheet 1 - correct referencing
Comprises two named ranges (range_1, range_2 resp.) which both refer to the exact same range (with identical scopes). Vlookups operate perfectly fine and produce identical results:
Besides their name, range_1 and range_2 are otherwise identical in every way per the following in Name Manager:
Sheet 2 - conflict / error
Copy of Sheet 1, with range_1 amended to only include the 1st column - the same vlookup functions as Sheet 1 now produce an error for range_1:
Note: copying the functions from Sheet 1 have now produced the following in Name Manager:
However, I'm still able to reference range_1 from Sheet 1 per the following tooltip that appears when I start typing '=range_1' in any cell within Sheet 2:
Thus its possible to retrieve what appears to be the 'correct' range for range_1 in any cell in the workbook by referencing the original scope (workbook), despite the vlookup in Sheet 2 producing an error.
It this is not the case (and you do not have 'duality' in scopes for the same named range) then the only other reason I can think of is inconsistency RE: formulation. If they are truly identical in the ranges they reference, then I would suggest adopting a single name (KNOTS, given this appears to function correctly) to simplify the workbook/functions and improve auditability.
Vlookup parameter (0/1)
RE: vookup(range, lookup, True/False) -
True (i.e. '1') parameter will return an 'approximate' match (which distinguishes this function from alternatives such as index/match). However, xlookup is advisable / preferred over vlookup in any case given it also has this feature and can reference to the left or right of the lookup column (vlookup works strictly to the right). Although it is more complex with additional parameters/arguments to consider. See here for details.
I have a pricelist, with currently 5 different categories of products. Each product will have to have two different prices. Depedning of the product and the type of price, the calculation will be different. Therefor I've used INDEX/MATCH to find the formula needed, from a table I created.
Below a screendump, and I wanted to attach the Excel fil, but canøt seem to work out how.
Question: HOW do I then "run" the formula I fetched? -I've tried different suggestions on using EVALUATION, but it doesn't seem to cut it? Also I've tried "Indirect' on the whole formula, without success.
I would like to avoid any VBA for this case.
Can anybody provide some insight?
You could but if I understand properly, the only thing changing in the formulas is the "muliplier" number, then it's better to lookup that number instead of the whole formula. The other method (which would use Evaluate etc) is not be considered "good practice" for a number of reasons.
EDIT:
I didn't see the 2nd varying value (since I was on the SO mobile app) but it's still not an issue since it would a target column. You could be thinking of the opposite: sometimes lookups based on multiple criteria can get complicated, but this a matter of more data, as opposed to adding criteria for the lookup.
VLookup would have been the simplest method, like G2 could have been:
=VLOOKUP(E2, $J$4:$L$8, 2, False)
...to return the second column of range J4:L8 where the first column equals E2. (Then for the next required column, same formula except with 3 instead of 2.)
Since I wasn't sure more columns could be added one day, I allowed for that by, instead of specifying "Column 2 or 3" etc, it finds the column dynamically by name. (So the multiplier/factor used in G2 will change if you change the title in G1 to the name of a different column existing in the target data chart.
For the sake of neatness as well as potential of additional columns like G & H, I moved the lookup table to a separate sheet. It can stay out of the way since you won't need to see or change it very often. (If the same chart was going to be referenced by many workbooks, you could even move it to a separate workbook and point all formulas at that, since it's always best to have one copy of identical data instead of many in different workbooks.
Also to assist with potential future changes (and just to be tidier), instead of referring to the target table range addresses (like "J4:L8" etc) I named two ranges:
the table of multiplier/factor data can be referred to by it's address, or by myMultipliers
the titles of the same table is also called myMultiplierTitles (used to match to the titles of column G & H on the original sheet.
Formula
After those changes, the lookup formula in G2 is:
=INDIRECT(VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0),FALSE)&ROW())*VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0)+1,FALSE)
INDIRECT returns the value of a cell that you refer to by name (text/string) as opposed to directly (as a range). For example:
=INDIRECT("A1")
returns the same as
=A1
...but with INDIRECT we can get the name from elsewhere (a cell, function or formula). So if x="A1" then =INDIRECT(x) returns the same as the 2 above examples.
Your original plan of storing the entire formula in a table as text would have worked with the help of INDIRECT and/or EVALUATE but I think this way is considered better practice partly because it facilitates easier future expansion.
The formula is longer than it would have been, but that's mostly because it's dynamically reading the field names. And size doesn't matter. :-)
How do you create formulas that will return the totals, averages, counts, min, max, etc from different worksheets? The columns (that exist) are consistent in their header information, but may or may not be different from one sheet to the next, column number wise. Let's say I have 7 tabs of data, some or all of them may contain a column heading of beans, for example, but the column numbers may or may not be consistent across all tabs, where present. Their actual locations within the worksheet are completely dynamic.
My spreadsheet has several tabs of raw data that I want to compare against in a summary/report sheet. I'm sure this can be done but I am afraid it is a little too far beyond the capability of this old brain.
I've thought about and toyed with a bunch of formulas using indirect, index, match and just can't figure it out. Your help would be most appreciated. Thanks
Here's a possible function only solution. The final result will look like:
We will use four(4) primary functions:
ADDRESS
INDIRECT
MATCH
LEFT
Note: Just follow the link if you have question on how to use these functions
The formula: This is in cell C4 Above
=AVERAGE(
INDIRECT(
"'"& C$3 & "'!" &
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
& ":" &
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
)
)
Edit1: To handle the comment below for headers beyond 26, change this
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
to this:
SUBSTITUTE(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),"1","")
Basically what is does is:
Find where the header Bean is located using MATCH function. To do that, you will have to incorporate the use of INDIRECT since your sheet name is dynamic (in this example, your sheet name is in C3 - Data1). (I assumed all your headers are in 1st row, I use 1:1 in there). Note: In this example, Bean is in column H of Data1 sheet
MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0) <~~ returns 8
After finding where it is, we need to get the entire column address so we can apply counting and summing functions (e.g. SUM,COUNT,AVERAGE etc...). To do that we use the ADDRESS function combined with LEFT to get the column letter.
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1) <~~ returns H
Then we just repeat that formula and connect it with : to get H:H
Now that we have the column address, we simply connect it again with the sheet name and apply the final INDIRECT function plus the counting and/or summing function of your choice.
Sample formula of Total in C5:
Sample formula of Max in C6:
Finally, all you have to do is copy the formula across all columns with sheet name. Just add sheet names beside the last one and copy formula. That's it. I hope this is close to what you want and I hope that all the functions I used are available in Excel 2000.
I am trying to return multiple values using multiple criteria...below is the code I have tried (but using the special brackets) but it keeps coming back as though I am trying to create a sum and have an error...
=IFERROR(INDEX(Sheet2!$C$4:$C$25,SMALL((IF(Sheet2!$D$4:$D$41=Sheet3!G2)*(Sheet2!$E$4:$E$67=Sheet3!$L$3),ROW(Sheet2!C4:C24)),ROW(1:1))),"")
Below is a code that returns one result, but there are multiple names for the two matching criteria.
=IFERROR(INDEX(Sheet2!$C$4:$E$43,MATCH(1,(Sheet2!$D$4:$D$26=Sheet3!$G$2)*(Sheet2!$E$4:$E$26=Sheet3!$L$3),0),1)," ")
essentially, I have a stakeholder analysis square - broken down into:
Keep Satisfied (Sheet 3: cell C2)
Manage closely (Sheet 3: cell G2)
Keep Informed (Sheet 3: cell C13)
Monitor (Sheet 3: cell GG13)
I am using a data validation in sheet 3: cell L11 (linked to Sheet 2), to create the second criteria (project).
What I would like to happen is for it to return the names into each of the stakeholder analysis headings. The problem is, if for example, I have 3 names in 'manage closely' for one project - I cannot get it to return all three names...only the one.
This has been driving me insane
There are several errors in the first formula you give, i.e.:
=IFERROR(INDEX(Sheet2!$C$4:$C$25,SMALL((IF(Sheet2!$D$4:$D$41=Sheet3!G2)*(Sheet2!$E$4:$E$67=Sheet3!$L$3),ROW(Sheet2!C4:C24)),ROW(1:1))),"")
For one, the ranges passed should be of an identical size; in your case, all four are different, viz:
Sheet2!$C$4:$C$25: 22 rows
Sheet2!$D$4:$D$41: 38 rows
Sheet2!$E$4:$E$67: 64 rows
Sheet2!C4:C24: 21 rows
I can only guess at what should be the correct range, so let's assume the largest for the sake of argument.
Secondly, I assume that the reference:
Sheet3!G2
should actually be absolute, i.e.
Sheet3!$G$2
so as to be invariable as this formula is copied down?
I will also make a few other corrections, to the value_if_true clause being used for the IF statement (the one you are currently using is not correct), and also to SMALL's k parameter (ROWS is more robust than ROW here: https://excelxor.com/2014/08/25/row-vs-rows-for-consecutive-integer-generation/).
All in all:
=IFERROR(INDEX(Sheet2!$C:$C,SMALL(IF(Sheet2!$D$4:$D$67=Sheet3!$G$2,IF(Sheet2!$E$4:$E$67=Sheet3!$L$3,ROW(Sheet2!$C$4:$C$67))),ROWS($1:1))),"")
and copied down.
You might also want to take note that, if the ranges being questioned are in fact quite large, the use of IFERROR can here be very inefficient:
https://superuser.com/questions/812727/look-up-a-value-in-a-list-and-return-all-multiple-corresponding-values/812848
Regards
I have a 12x18 Excel range which draws data from a 823x20 sheet (Results!$A:$T) according to the 12x18 range's page, row and column headers (criterion1, criterion2 and criterion3, respectively)
={INDEX(Results!$A:$T,
MATCH(1, (criterion1 = Results!$A:$A) * (criterion2 = Results!$B:$B), 0),
MATCH(criterion3, Results!$A$1:$T$1, 0))}
As you can see, it's not that much data, but still, when I change the page header, my computer (2 GHz Intel Xeon with 24 GB of RAM) takes about a minute to update the 216 (12x18) index searches and I'm not even half way done with creating searches.
Earlier on my project, these searches only had one criterion, so I used VLOOKUP() and the results came very quickly. However, now I need to find values according to three criteria, and the function above is the best way I've managed to accomplish this. However, it seems to be the responsible for the long computation times I'm getting. So my question is: how can I optimize a VLOOKUP() of multiple criteria? Should I tweak INDEX(1, MATCH()*MATCH(), MATCH()) or is there a faster way to do this?
Here's a sample of the 12x18 index searches (branch name is the only variable that the end-user will be able to change):
And of the 823x20 sheet it searches (column A has no merges, actually):
For a summary and options for Lookup with multiple criteria you may check this.
I use a lot Method 2 here (it is non-array formula) and method here.
I guess you should try them to check their speed.
First of all, can't this be accomplished simply by filtering on column A in sheet 'Results'? I think that is the most straightforward solution.
However, I have created an example workbook based on the criteria you described. It can be found here
First I created a list of the unique branches by using Advanced Filter for unique values on sheet 'Results' column A and put them on sheet 'Lists' where I created a named range listUnqBranches. I used that named range to create a data validation drop-down list on sheet 'Sheet1' cell A1 so that users can select which branch they'd like to see. I named that cell Branch.
Next I created two named ranges. rngDate is defined with this dynamic named range formula:
=INDEX(Results!$B:$B,MATCH(Branch,Results!$A:$A,0)):INDEX(Results!$B:$B,MATCH(Branch,Results!$A:$A,0)+COUNTIF(Results!$A:$A,Branch)-1)
rngLookup is defined with this dynamic named range formula:
=INDEX(Results!$C:$C,MATCH(Branch,Results!$A:$A,0)):INDEX(Results!$T:$T,MATCH(Branch,Results!$A:$A,0)+COUNTIF(Results!$A:$A,Branch)-1)
Lastly, in sheet 'Sheet1' cell B2 and copied over and down is this formula:
=IF(Branch="","",INDEX(rngLookup,MATCH($A2,rngDate,0),MATCH(B$1,Results!$C$1:$T$1,0)))
Note that the formula solution with named ranges is dependent on the data in sheet 'Results' being sorted by Branch. Does that work for you?