Excel: How to lookup a value that has multiple search criterias? - excel

I'm looking to implement a formula that would return the total quantity attributed to a certain ID. I was relying on a classic IfError and Vlookup combo to get the data, but I have many suppliers that use the same vendor code (supposedly unique ID) for different branches working on different commodities (which act as separate entities from a logistics perspective).
I have to manually split up the quantity attributed to certain suppliers by looking for the logistics agent responsible for them, and when the same log agent handles multiple commodities for the same supplier, I manually dig for the material codes.
I would like to know how to synthesize the manual process I undertake in a single formula.
I was using this formula to get the data in a pivot table =IFERROR(VLOOKUP(TRIM(A2),Pivot!$A$4:$B$105,2,0),0)
And I need to incorporate three search criteria to get the qty of a specific supplier's sub-entities (Vendor ID, name of Log Agent, Material ID).
[Part of pivot table where I'd get data pasted as value ][1]
[Example of how the data is stored and result I get with Vlookup function][2]
[1]: https://i.stack.imgur.com/A1v0f.png
[2]: https://i.stack.imgur.com/BmFi3.png

With the following solution, you will need to fill all the cells with vendor id and PURCH_GRP_NAME. If the range is built from a pivot table, there is an option to "repeat" the identical values on every row.
Once this is done, you can use a formula like this (the XXXXXX is the search criterion. I did not understand where this is supposed to come from):
=INDEX($D$1:$D$105,MATCH(XXXXXX,$A$1:$A$105&$B$1:$B$105&$C$1:$C$105,0))
Press Ctrl+Shift+Enter to turn it into a matrix formula.

Related

VLOOKUP to bring data from another sheet

I have a table containing a some football data, such as Country, League, Teams, Standing table information, such as total matches played, wins, draws, losses, goals scored and conceded, and so on.
Here's a file download link
It contains two sheets.
First sheet is STANDINGS_EXTENDED:
I need to fill these 3 tables with the data contained in another STANDINGS worksheet.
Here's a screenshot of the STANDINGS sheet:
My aim is that once I fill LeagueId and Group Id (which is optional) fields then inside all three tables will be produced the data as in this sample.
I wonder if it is possible to achieve this without VBA. But i have no clue on where to start from. I tried is several different ways, but i get only first result from STANDINGS worksheet for any league i enter.
Looking forward to your help.
Thank you!
UPDATE:
So far I could get the count of rows related to Overall, Home and Away using these formulas:
=COUNTIFS(STANDINGS!E:E;STANDINGS_EXTENDED!E1;STANDINGS!F:F;"StandingsOverall")
=COUNTIFS(STANDINGS!E:E;STANDINGS_EXTENDED!$E$1;STANDINGS!F:F;"StandingsHome")
=COUNTIFS(STANDINGS!E:E;STANDINGS_EXTENDED!$E$1;STANDINGS!F:F;"StandingsAway")
Also, what I can get is the first row of these results using this formula:
=VLOOKUP($E$1;STANDINGS!$E:$V;4;FALSE)
What I need to figure out is how to modify above formulas so that I fill tables with remaining rows.
In order to do this you need a formula in every single field of your 3 tables that link it to data on the Standings tab. That would be 13 x 3 x 20 formulas. Therefore one would try to create formulas that can be copied, in the best case less than 13 original ones, but definitely one formula for each field.
Each formula would look for a unique identifier in the Standings list. I can't see any unique identifiers there but you might create them by concatenation, such as "League" + "Country" + "Position". The more detail you need the larger the formula. The key is: without a unique identifier for each row you can't retrieve data. But once a row has been identified you can get the value from any of its columns.
If your tables sometimes have 12 rows, sometimes 20, and sometimes 25 you must provide space for the possible maximum and then design your formulas to return a blank if there is nothing to display.
In conclusion, the core of your system is in the Standings table. It must be set up so that data can be retrieved from it. Ideally, your selection on the Standings Extended sheet would generate a concatenated unique identifier for a list to which you can add the fixed number in the Pos column to identify individual rows in the Standing table. As long as you can't identify rows no data can be retrieved.
Using VBA gives you more flexibility but doesn't relieve you of the task to create uniquely identifiable rows.

Calculate average of values in a column based on matches of two variables in two other columns

I'm having an issue with some data that I'm working on that has had me stuck for a while.
I'm working on some patient data for a clinical practice that has each patient encounter logged on a separate line with an account ID, date of service, the height and weight measurements for that date, and other variables.
Aside from VLOOKUP and the usual formulae/functions I've got a pretty rudimentary understanding of Excel but I can pick up on things fairly quickly.
In the data I've got each line tied to a patient account ID as well as what quarter the DOS was in. For patients with multiple visits, they will be identifiable by repetitions of the account ID number on other lines.
For some patients, there will also be repetitions in the quarter if the same patient was seen twice in the same quarter. This is where I need help.
I'd simply like to average the value of a variable for each patient in each quarter. I'm not sure if AVERAGEIFS is the right function to use but I need an operation that checks for matches in a line of both account ID and quarter (Q1, Q2, Q3, or Q4) with the other lines in the sheet and comes up with a quarterly average for the variables in question.
What I have
What I need
If I'm understanding your question, you could use AVERAGEIFS to accomplish what you are asking. With excel, a lot of how successful an approach will be is determined by how your data is structured, and if/how often you are planning on updating your work.
It would be easier to give a concrete answer with an example of the data you are looking at.
If your source data is in columns A:D something like:
and you are looking to summarize the weight data in I by account ID and Quarter:
you could use AVERAGEIFS(C:C,A:A,G2,B:B,H2) this would find the cells in column A that match the value in G2, find the cells in column B that match the value in H2, and report the mean value in column C of the matching rows.
An alternative is to use a pivot table, which automates a lot of what you are trying to do. For that approach you would select your data block, and click on Insert>>Insert Pivot Table (at least in my version). That should bring up a wizard. Accepting the defaults will create a new sheet. Then look on the right side of your window, and you should see a list of your column names near the top, and four boxes called Filters, Columns, Rows, and Values. You should be able to drag and drop your columns into these boxes to get summaries of your data. If you add your Account ID and Quarter tabs as columns, and your height and weight as Values, then right click on each of the value columns and select "Value Field Settings" and select Average from the menu that pops up. That should give you something that looks like:
At that point, you can change the formatting to make if fit your needs, or copy data somewhere else.
The AVERAGEIFS approach will automatically update if you add more data, but will only summarize things that match the values you list. If there is an account ID/Quarter pair that isn't in the summary column you won't have any idea it's there. If you are summarizing an ID/Quarter pair that isn't in your data you'll end up with a division by Zero error like in the example.
The Pivot Table option only updates when you manually click refresh (right click and choose refresh pivot table from the menu), but will summarize all the data based on the columns you've selected. It's also a little more robust as you avoid having to type out the formulas and make sure you are pointing to the right column. This option also by default provides nested summaries; you can turn the subtotals and grand totals off if you want.
I used the function:
=SUMPRODUCT(($B$2:$B$13="Customer 1")*($C$2:$C$13="Q1"))
Where Customer 1 could be a user id and Q1 you can change to which quarter you want.
Excel screenshot

Excel VLookUp But Only Once

I have an Excel spreadsheet with one tab of our inventory of cars showing their make, model and serial number. I also have another tab showing our customer orders for cars but they only contain make and model. I want to match the custom orders to the inventory but I need them to only match once per serial number.
For instance, I have three customers wanting Honda Civics. I only have one on hand. Currently, VLookUp will match each customer to the same one so it appears as if I can fulfill all three orders; which of course I can't. I only have one.
I believe I am going to need something more flexible than VLookUp.
I am hoping that I can find a formula smart enough to match orders to inventory only once, then to ignore that match when moving onto the next order. This way I know exactly how many I can actually fulfill.
Here's an array-formula requiring the following structure:
Make & Model are combined into a single cell for both customer requests and your stock.
Your stock has named ranges for its 2 columns: MakeModel and Serial. The ranges can include headings, but they MUST both start in row 1.
Your customer requests start in A2.
Enter this array-formula in B2 only:
=IFERROR(INDEX(Serial,SMALL(IF(MakeModel=A2,ROW(MakeModel)),COUNTIF($A$2:A2,A2))),"Insufficient Stock")
To enter an array-formula, you need to press CTRL+SHIFT+ENTER. After entering the array formula, then fill it down.

Using arrays and table names for unique value list

I am building a summary tab in an excel workbook that is linked to numerous other workbooks to track hierarchical business data (ie. Numerous files for subordinate teams exchanging data with a master workbook that tracks them all). To make it easier and to increase uniformity, I'm using tables for all of the data and "building" table names based on each spreadsheet's specific criteria -- then using INDIRECT to bring the table references to life and complete my calculations.
To simplify the formulas I'm using, I've been using arrays to check all tables at once for pieces of data. For example, I've built a table for subordinate units (Ref_Units) which contains the units' names: ABC, EFG, XYZ. I then have a table (Ref_Tables) translate my Ref_Units into standardized table names. Formula is something like {=Ref_Units&"_2016_Sales_Rpt"}. Now I can make some SUMIFS using Ref_Tables that look in several different locations for data -- and to make updates, I only have to change Ref_Units.
My Summary tab will be the culmination of data coming from a dozen+ tables and upwards to 10 workbooks. The basis of the summaries are gathered from drop down lists specifying categories and years being summarized; these values are plugged into some INDIRECT formulas to generate table names and voila.
Now, the problem: let's say each unit records sales numbers and projections for specific items like "televisions", "stereos", "flatware", "candles", etc. and each of these items has also has a category accompanying it: "Electronics","Homewares", "Decor", etc.
I want a summary spanning all of the units' data pulling the numbers in each category (I should note that categories may change each month, so the list must be dynamic). To make the list dynamic (and to give myself the ability to summarize based on other criteria), I am using a formula I found online to generate a list of unique/distinct values.
Right now, I'm using INDEX/MATCH and COUNTIF to generate a unique list of categories. So, my unique list starts in cell C9 and the formula looks something like this:
{=iferror(INDEX(INDIRECT(Ref_Tables&"[Category]"), MATCH(0, COUNTIF($C$8:C8, Ref_Tables&"[Category]"), 0)),"")}
This function will not work. The only way I can get the desired results is to input multiple iterations of the formula, each using a single table name from Ref_Tables and joined with &.
Example:
{=iferror(INDEX(INDIRECT("ABC_2016_Sales_Report"&"[Category]"), MATCH(0, COUNTIF($C$8:C8, "ABC_2016_Sales_Report"&"[Category]"), 0)),"")&iferror(INDEX(INDIRECT("EFG_2016_Sales_Report"&"[Category]"), MATCH(0, COUNTIF($C$8:C8, "EFG_2016_Sales_Report"&"[Category]"), 0)),"")&iferror(INDEX(INDIRECT("XYZ_2016_Sales_Report"&"[Category]"), MATCH(0, COUNTIF($C$8:C8, "XYZ_2016_Sales_Report"&"[Category]"), 0)),"")}
**Remark: the look up arrays are strangely input here because they are actually cell references pulling in table name and column name being looked up, then brought to life with INDIRECT
Partially my problem is that the resulting formula is about 10 lines long which looks horrible, but it also looks too confusing to anyone using the workbook.
Is there any way to get the INDEX/MATCH to look at multiple tables for generate the list that is more concise?
I should note that my boss refuses to use VBA/macros/pivot tables because there are not many in my office skilled enough to troubleshoot issues in these areas. Help?

Advanced Dynamic Validation Lists in Excel

While a number of other posts address similar issues, I was unable to find one that met my specific needs, using multiple sheets, etc.
What I need is the ability to select a value from a validation list in one column, and then have a second validation list be narrowed to just the values that can be selected based on the first validation list, and then a third that follows the same logic, etc.
So for example, I have 5 sheets:
Log - This sheet is used for input and will contain the columns that
have the dropdown validation lists.
Clients - This sheet is a two column list of clients. Column A has
the Client ID, column B has the Client Name.
Matters - This sheet is a three column list of Matters. Column A has
a Client ID, Column B has the Matter ID, column C has the Matter
Name.
Timekeepers - This sheet is a two column list of Timekeepers. Column
A has the Timekeeper ID, Column B has the Timekeeper Name.
Rates - This sheet is a three column list of Rates. Column A has a
Matter ID, Column B has a Timekeeper ID, Column C has a Numeric
Rate.
The log sheet:
Column A (Timekeeper) will be a simple validation list dropdown from which I will select a timekeeper (by name). This validation list is populated by the list on the Timekeeper sheet.
Column B (Client) will be another simple validation list dropdown from which I will select (by name) a client. This validation list is populated by the list on the Clients Sheet.
Column C (Matter) will have a validation list of Matters. This is the first dynamic validation list, as the list should only show the matters that belong the to client that was selected in Column B. We know which matters belong to a client by the Column A (Client ID) in the Matters sheet.
Column D (Rate) will simply display the rate for a given timekeeper/matter combination. We would now have the matter id and client id from the input into columns A and C, so we just need to locate the row in the Rates sheet that has that matter id and timekeeper id.
The solution can use VBScript or not, whatever you prefer. I'm a software developer, so I'm comfortable with VBScript, and I'm relatively familiar with Excel, so nested built in functions would be fine too.
Thanks in advance!
EDIT:
This workbook is going to be dynamically generated from a database, so I need to utilize an approach that can be generated programmatically.
The "Log" sheet will contain many rows where the user will select a Timekeeper from a dropdown, then select the Client from a dropdown (which will limit the Matter dropdown list) then select a matter from the Matter dropdown (which, combined with the selection in the timekeeper field will determine the "Rate").
The dropdowns will show the "name" values (i.e. timekeeper name, client name, matter name) but the limitations to subsequent lists based on these selections has to be based on the "ID" value for the selected "Name".
An example showing how to use subsequent list limitations would be most helpful. All of the examples I have seen show how to select one value and limit a second list, but I need to be able to have the selection from the second list limit a third list, the third list limit a fourth list, and finally, the "rate" is determined by what is selected in two of the lists.
The gist of dynamic validations is using =INDIRECT(SomeNamedRange) as the Source data in the List type of Data Validation.
Now, the hardest part is to dynamically generate this list of partners. For the sake of this example, I'll assume you have three sheets: Sheet1, Config, and Validation. I'm also assuming you are selecting a Partner based on a Region, as that is a simpler example.
Let's start with Validation.
Here's an example of my data:
Notice how I've sorted the data based on the most general criteria (Region, in this case). This will be important later on. Also notice that I've named A1:A26 as Validation.Region. I've also named B1:B26 as Validation.Partner.
Config is where your magic happens.
Moving over to the Config, we're going to need to add a list of unique regions, and an address describing where they're located. We'll name this address Region.Choices.
For this example, I used the COUNTIF function to find the last partner in the list. The exact formula was ="Config!$B$2:"&CELL("address";OFFSET(B$2;COUNTIF(B$2:B$230;"?*")-1;0)). Unfortunately, Excel doesn't have a built-in function for the sheet's name, so I had to hardcode that. I went ahead and hardcoded $B$2 to improve performance (maybe?), but you could do that dynamically too.
Sheet1 is where you'll be making your dynamic selection.
In this sheet, we have the following structure.
Take B4, name it "Region.Selected", and add Data Validation as a List of Source =INDIRECT(Region.Choices).
Creating the logic behind the dynamic drill down
Now go to Config, and replicate the contents of B1 on C1, making sure to alter the hardcoded $B$2). Finally, name Partner.Choices, and type in the following Array Formula in C2:C100:
=IF(Region.Selected="";OFFSET(Validation.Partner;1;0;COUNTA(Validation.Partner);1);OFFSET(Validation.Region;MATCH(Region.Selected;Validation.Region;0)-1;1;COUNTIF(Validation.Region;Region.Selected)))
Note: to add an Array Formula, select C2:C100 before typing the formula, and once you're done typing, hit Ctrl+Shift+Enter instead of Enter.
While it may seem convoluted at first, this is basically returning every Partner if no Region is selected, or returning the partners from a selected Region by calculating where it ends and starts and shifting one column to the right with OFFSET.
Wrapping up the dynamic drill down
Now go back to Sheet1, take C4, name it "Partner.Selected" (for consistency), and add Data Validation as a List of Source =INDIRECT(Partner.Choices), as displayed below:
For this example, I used the COUNTIF function to find the last partner in the list. The exact formula was ="Config!$C$2:"&CELL("address";OFFSET(C$2;COUNTIF(C$2:C$230;"?*")-1;0)). Unfortunately, Excel doesn't have a built-in function for the sheet's name, so I had to hardcode that. I went ahead and hardcoded $C$2 to improve performance, but you could do that dynamically too.
Now go ahead and test your dynamic validation! It should look like this:

Resources