Searching 2D Excel array for a value, returning the value of the adjacent cell - excel

I've been scouring this website throughout my last 2 programming classes, and decided it was worth joining this fabulous community!
In a nutshell, I want to create an "invoice maker", which allows one to first select a category via a dropdown box in A1, then an item within that category with a dropdown in B1. Excel would then autofill the price in the next column C1.
Essentially 2 (not sure what to call it: cascading, nested, dependent) dropdown boxes that when both filled, return a price. For example:
A B C
1 Category Item [Price]
Both dropdowns use Data Validation referring to a Defined Name, which is based on an array in sheet "Database". This sheet is formatted like so:
category1 price category2 price category3 price category4 price ...
item1 $xx item1 $xx item1 $xx item1 $xx
item2 $xx item2 $xx item2 $xx item2 $xx
I used this column arrangement mainly because it allows for each category to be expanded indefinitely. If you see a simpler way, let me know!
Essentially, to print the price in C1, my objective is to find the item name in the 2D Excel database, and return the cell immediately to the right of it. Ideally the formula in C1 would use cell A1 to determine which category to search, and search this column for the corresponding item name in B1. Then, it would +1 offset that to the right, thereby referring to the price.
As far as formulas, I have some rough pseudocode, but I'm confused between VLOOKUP, OFFSET, MATCH, and INDEX. Basically:
=INDEX( "defined name of my entire database" , MATCH( B1, **column corresponding to chosen component** , 0 ) + 1 , MATCH( A1 , components , 0 ) )
The way I see it, the INDEX would return the value of row+1 item, in a given column. The first MATCH would find the row in which the item is found, and the second MATCH would determine the column that category is found in.
Now my question is, how do I make the first MATCH search ONLY the column which corresponds to the right category?
Honestly I have no idea if my pseudocode is correct. I translated it to Formula, and it simply returns #N/A in the cell.
Many thanks for any help!!!

I would try the following approach:
Take the first column of the database sheet and offset it so many columns to right how the searched category is offset from the left. Then we have the price column of this category because we have offset it 1 column if it matched the first categrory, 3 if it matched the second category and so on.
From this column indicate the value from the row which is the same as the row in the found offset-1 column (the category column) which matches the searched item name.

Related

Fill in table based a column of categories in Excel

I have a table that looks like this:
Type Value
Movie 5
Food 3
Gas 10
Food 2
.... ....
And There's a second table I want to fill in with "Value" based on their type in the first table, so that the corresponding rows look like this:
Rent Food Movie Gas Clothing ... ( appear in specific order bc they are subcategories)
5
3
10
2
The title row is already there, so I was thinking there might be some kind of lookup method to do this? How do I do that?
your second table apperas to hold one value per row but it doesn't have a label. it does correlate to the original row number, is this by design or coincidence?
if this is by design then you can use those 2 columns, hide them if you like, get a unique list of categories by copying you r abels to a new colum, removing duplicates in the data tab, then paste special transpose in c1 to create colum headers.
so column a and b remain unchanged
row 1 contains header starting at column c
your data starts at c2
this is the formula
=Iferror(vlookup(C$1,$A2:$B2,2,false),"")
drag it down and to the right
you can copy paste special values when done to remove the formulas
for something with only a hundred or thousand cells this will be one of the easier options but i would not do this on large tables, for those i would use power query or VBA
Assuming your 1st table is in Sheet1 and 2nd table is in sheet2.. you may try to fill in Sheet2!A2
=IF(Sheet1!$A2=A$1,Sheet1!$B2,"")
and drag it all the way.. Hope you get how it works.. and what you need.

Using Correl Function in Excel for Varying Array Sizes

So the current setup of the problem at hand is that I have 4 columns, Employee ID, Category 1, Category 2, and Category 3. I need to find the correlation between Category 1 & Category 2, Category 1 & Category 3, and Category 2 & Category 3 for each Employee ID. The issue is that the array length for each Employee ID is different. Some employees will have 5 records, some employees will have 8 records to their ID.
This problem would be simple if the Subtotal button had the CORREL function built into it given its grouping by feature.
How would I go about calculating the 3 correlation coefficients for each unique Employee ID? Excel function or VBA works
You need to use an array formula. Please see this screen shot of a sample situation:
As you can see the formula for cell G2 is: =CORREL(IF($A$2:$A$16=F2,$B$2:$B$16,""), IF($A$2:$A$16=F2,$C$2:$C$16,"")) That is saying if cell in column A matches your employeeId, include the cell in corresponding column in the array (Column B for the first IF and Column C for the second ID). After entering in the formula you need to make sure you hit Ctrl+Shift+Enter to tell excel you want to do an array formula or Command+Enter on a Mac.
You obviously need to modify the formula to fit the size of your data and you can copy that formula to any cells if you setup your $s correctly.

MIN function in Excel

I need to find minimums in a list of companies and prices. For example in one column I have apples, pears and grapes. For each of these there are several sellers and each of them has a different price. The list in the A coulmn would be Apple, Apple, Apple, Grapes, Grapes, Pear, Pear, Pear, Pear. In B would be Target, Trader Joe's, Harris Teeter etc... And in column C would be the price. Fruits in column A are in alphabetical order. I need to find a separate minimum for every fruit. I can do that manually except I have thousands of rows of data.
I'm thinking along the lines that I need to specify the area in which I want to return the minimum from. That would be as long as the entity in column A is the same, that's the area.
Does anyone know a solution for this problem?
If data starts at row 2 (headers in row 1) try this formula in D2 copied down
=IF(A2=A1,"",MIN(OFFSET(C2,0,0,COUNTIF(A:A,A2))))
That will give you the minimum price on the first row of each fruit. Filter column D on non-blanks to see just the minimums
Use a combination of IF and MIN
=MIN( IF ( logical_test, value_if_true, value_if_false ) )
e.g.
=MIN( IF ( A2:A100="Apple", B2:B100, 0 ) )
You can use PivotTables:
Select your data and insert a PivotTable:
Choose a location to put it. I'll put it in the same sheet:
Click, drag and drop the fruits under Row Label and the Price under Row Values:
Right click on the PivotTable and pick Summarise by > Minimum:
And you should end up with this:

Excel: Match\Index specific column based on multiple criteria

I have two Tables, Table 1 Column A is a rolling date column. Table 2 consists of four columns of differing "Trigger Dates". Table 2, Column 1 contains an Annual trigger, ie occurs once a year. Table 2 Column 2 contains Bi-Annual Triggers, and occurs twice yearly. Table 2 Column 3 contains Monthly Triggers, "12 dates" and Table 2 Column 4 contains Weekly Triggers, "52 dates".
Ok, so what I'm looking for is to a formula that will return the date trigger, where Table 1 Column 1 matches a condition (Annually, Bi-Annually, Monthly, Weekly) selected in a cell "we'll say F1, outside of any ranges that may be created.
Example: If Table 1 Col 2 = "01/02/2013" and I select "Weekly" in F1, the formula will look in the weekly Column in Table 2 to determine if "01/02/2013" exists.
I've allocated a named range to each column in Table 2
I've allocated a named range to the condition in F1 which is a drop down list
Any suggestions?
You might try:
=IFERROR(VLOOKUP(B2,INDIRECT(CHAR(72+MATCH(F$1,$I$1:$L$1,0))&":"&CHAR(72+MATCH(F$1,$I$1:$L$1,0))),1,0),"")
Ok, so supposing your Range Name is in F1, your formula to find the match would look as follows:
=If(IsError(Match(LookupVal,Indirect(F1),0)),"No Match", "Match")
...Something along those lines
Hope this helps point you in the right direction.
INDIRECT and VLOOKUP will be your friends here.
I constructed Table2 just as you had described, with the Annual,Bi-annual,Monthly,Weekly labels for the columns in the table - this will avoid having to keep named ranges up to date, as it's looking directly at the table in the formula
For the function, I then used VLOOKUP to find the date, in the column referenced by F1.
Column Reference: INDIRECT("Table2["&$F$1&"]")
Find Value: VLOOKUP([#Col2],INDIRECT("Table2["&$F$1&"]"),1,FALSE) (looking at column 1 in the return values, as I don't really care what value is returned.
This will return the date if found, and an error if not. I can then wrap the result in the IF(ISERROR( so I can return Yes or No if the date is found.
This produces the entire formula of
=IF(ISERROR(VLOOKUP([#Col2],INDIRECT("Table2["&$F$1&"]"),1,FALSE)),"No","Yes")
for the next column in Table1, so that when I change the value in F1, it will look for that column name in Table2, and let me know if it is found.

return the nearest number value above current cell within a list in Excel 2010

This is a little difficult to explain but I have a list of data, all in one column, that contains a department number and then below each department number is a long list of brands that correspond to that department number. So within this list there are multiple departments with brands listed underneath them.
My goal is to somehow return the value of the department next to each brand but because the department number is located above the list of brands and the data is changing each time I repull the report, the row numbers will not remain them same and there may be duplicate brand names, and I cannot figure out what formula to use because it is all contained in one column.
I need to come up with some type of formula that doesn't just search, but returns the value of the next number or value above the current cell and skips all of the text or blanks in between so it will grab the department number above it. Is there a way to do this or a better way to accomplish the goal of assigning each brand to the department above it while allowing for changing data each time I pull the report?
I tried replacing all of the text with 0's or blanks and then used the indirect function to say: =IF(BG24="",INDIRECT("BF" & ROW() - 1),""), but I assumed it would continue to loop and skip the zeroes or blanks until it found a number, but it did not, it just returned the zero value.
If I understand your problem correctly, the following formula should do it. Put it in cell B2. In cell A1, I'm assuming that there's the department number.
=IF(ISERROR(A1*1), IF(ISERROR(A2*1), B1, ""), A1)
This will work for a table like the following where no brands are numbers only:
1
Brand1
Brand2
2
Brand1
Brand2
To become:
1
Brand1 1
Brand2 1
2
Brand1 2
Brand2 2

Resources