Calculations that have variable cells in Excel - excel

I thought I understood Excel well enough until my boss asked me to do something in excel that involved MATCH and INDEX and for the life of me I can't figure out how those functions work. Perhaps more appropriately, I can't figure out how they're working in the spreadsheet I'm looking at. I'll just walk you through carefully what I'm trying to do.
I start by creating a drop down list which is no problem. The drop down list is a list of what is essentially probability tables. To skip past some irrelevant math, each table will have a single number that is generated from all of the numbers in the table that will be used in some calculations in other parts of the spreadsheet. Each of these tables will also have a name (top cell) that matches an entry in the drop down list.
[If anyone knows how to format this question so that it is a little easier to follow my question please, please feel free to tell me how. I don't know how to format stackexchange questions for excel worth anything.]
So ultimately, I have two main tables that are preforming calculations. The calcuations themselves are irrelevant. What is relevant is that I need to be able to add in a value into the calculation that can change depending on what is selected from the drop down list. So let me try to give an example.
Lets say I have this table:
| Month | Balance | Interest Rate |
|:--------:|:-------:|:-------------:|
| January | 100.00 | 1% |
| February | 101.00 | 1% |
| March | 102.01 | 1% |
| April | 103.03 | 1% |
| May | 104.06 | 1% |
| June | 105.10 | 1% |
I want the interest rate to be dependent on the drop down list so that perhaps I have set up where my drop down lists is generated from a table of cells that is something like this:
| Interest Rate |
|:-------------:|
| Low |
| Medium |
| High |
And I have three tables labeled "Low", "Medium", and "High". Each of these tables will preform some calculation to get the final Interest Rate result that will be the number that shows up in the top table. So that if I select "High", my table will look like this instead.
| Month | Balance | Interest Rate |
|:--------:|:-------:|:-------------:|
| January | 100.00 | 5% |
| February | 105.00 | 5% |
| March | 110.25 | 5% |
| April | 115.76 | 5% |
| May | 121.55 | 5% |
| June | 127.63 | 5% |
I'm pretty sure I need index and match functions to do this. I'll even put in a formula that is doing something close to what I'm doing but I can't seem to decipher how everything is working.
=INDEX($U$13:$BM$416,MATCH(D12,$T$13:$T$416,0),MATCH($A$13,$U$11:$BM$11,0) + 1) * SUM(P:P)
I know that that doesn't mean much when you can't see the worksheet, but that formula is doing very close to what I need to do. I guess my ultimately question is just if anyone will help walk me through how I could accomplish this in Excel?
EDIT: Here's a better glimpse
Lets say I have these 3 tables that show interest rates for various different things (e.g. Auto Loan, Mortage, Credit Cards). The "######"s are just showing that there are values in those cells that are used to calculate the numbers at the bottom (0.01, 0.03, etc.). Lets also say that the range in excel for these 3 Data Tables is A1:I6.
| | DataTable 1 | | | DataTable 2 | | | DataTable 3 | |
|:------------:|:---------------:|:-------------:|:------------:|:---------------:|:-------------:|:------------:|:---------------:|:-------------:|
| Low,Interest | Medium,Interest | High,Interest | Low,Interest | Medium,Interest | High,Interest | Low,Interest | Medium,Interest | High,Interest |
|--------------|-----------------|---------------|--------------|-----------------|---------------|:-------------|-----------------|---------------|
| ####### | ####### | ####### | ####### | ####### | ####### | ####### | ####### | ####### |
| ####### | ####### | ####### | ####### | ####### | ####### | ####### | ####### | ####### |
| 0.01 | 0.03 | 0.05 | 0.02 | 0.04 | 0.06 | 0.10 | 0.20 | 0.30 |
I have a drop down list in A8 that contains the values Data Table 1, Data Table 2, and Data Table 3.
Lets say I have another table (Range is K1:M14) that looks like the 1st table in this question.
| Month | Balance | Medium Interest |
|:---------:|:-------:|:---------------:|
| January | $100.00 | 3% |
| February | $103.00 | 3% |
| March | $106.09 | 3% |
| April | $109.27 | 3% |
| May | $112.55 | 3% |
| June | $115.93 | 3% |
| July | $119.41 | 3% |
| August | $122.99 | 3% |
| September | $126.68 | 3% |
| October | $130.48 | 3% |
| November | $134.39 | 3% |
| December | $138.42 | 3% |
I wrote a formula that would determine how the 3% gets into the Medium Interest column.
=INDEX($A$6:$I$6,MATCH($A$8,$A$1:$I$1,0),MATCH($M$2,$A$2:$I$2,0))
It works when I choose Data Table 1 in the drop down list. It correctly places 3% which is the medium interest rate for Data Table 1 but when I choose either of the other 2 data tables, I get an invalid cell reference error. This is essentially what I need to do in my real spreadsheet.

Not sure I can say how to do what you want, but I can at least explain MATCH and INDEX and what your formula is doing with them - hopefully that will be enough!
MATCH(what,in_where,match_type) will return the index of what in the array/range in_where based on the match_type. The "best" match_type is 0 - like in your example - which means "exact match". The other options are 1 for "less than" and -1 for "greater than" - both requiring you in_where to be sorted...
So you first example MATCH(D12,$T$13:$T$416,0) is looking for the exact value that is in D12 in the range $T$13:$T$416.
INDEX(in_where,row,column) will return the value in the array/range in_where at row row and column column.
In your example, you are looking in the range $U$13:$BM$416 with the row/column given by the MATCHes... The first MATCH is looking for D12 roughly in column T and the second is looking for A13 roughly in row 11. (I.e. it looks like your "table" has headers in row 11 and "keys" in column T and you are searching for the intersection of their locations.) The +1 in the column will be to correctly align the index returned by the MATCH and the the column number for the INDEX...
Without seeing this (e.g. file somewhere like dropbox, or a screengrab) it is hard to say more - but I hope this helps!
Btw - INDEX & MATCH as a combination can also be a good replacement of VLOOKUP if your "key" column is to the right of the "value" column that you want (or if you have a wide table and any change within it force loads of recalculations)
UPDATE based on second part of question
The new example gives the formula: =INDEX($A$6:$I$6,MATCH($A$8,$A$1:$I$1,0),MATCH($M$2,$A$2:$I$2,0))
INDEX will return the value for the given row/column. In this example your "table" is a single row $A$6:$I$6 so you would need to give just row 1 here - you aren't looking in a grid, but just a list.
So, you are looking to find the interest value for the interest level (Low/Medium/High at the top of your table) in the right DataTable (selected from a drop down). There are a few ways to do this, depending on the control you have...
Create a real data grid with Low/Medium/High down the side, 1/2/3 along the top and the % inside - then use INDEX as originally planned... MATCH the selections to the row/column
If that is a bit much to do, how about creating a new "compound key" to your table... e.g. Row 2 could contain 1_Low, 1_Medium, 1_High, 2_Low, etc. You then use just one search, but with a concatenated key : =INDEX($A$6:$I$6,1,MATCH($A$8 & "_" & $M$1,$A$2:$I$2,0))
Otherwise, you would first need to find "DataTable 1" in the first header row and use that to restrict the range to search for the interest rate level header... It is a bit more complicated and would depend more on the details of your tables (e.g. are they all the same number of columns - Low/Medium/High - or do some have Very High)

The formula for the 3% in the Medium Interest column should be:
=INDEX(A6:I6,,MATCH(A8,A1:I1,0)+1)
This formula returns the value in the index array A6:I6. Since there is only one row of data in the array A6:I6, it is not necessary to specify the row position for the index function. That is why there are two commas together - the row reference is missing and is not necessary. MATCH supplies the column number reference for the function based on your drop down list, which will be the values 1, 4, or 7 and then +1 to move over one more column. MAKE SURE that in cell A1 you have "DataTable 1", in cell D1 have "DataTable 2", and cell G1 have "DataTable 3".

Related

EXCEL: SUMIFS criterion applied to a INDEX MATCH search equals a value

I've spent pretty much all day trying to figure this out. I've read so many threads on here and on various other sites. This is what I'm trying to do:
I've got the total sales output. It's large and the number of items on it varies depending on the time frame it's looked at. There is a major lack in the system where I cannot get the figures by region. That information is not stored in the system. The records only store the customer's name, the product information, number of units, price, and purchase date. I want to get the total number of each item sold by region so that I can compare item popularity across regions.
There are only about 50 customers, so it is feasible for me to create a separate sheet assigning a region to the customers.
So, I have three sheets:
Sheet 1: Sales
+-----------------------------------------------------+
|Customer Name | Product | Amount | Price | Date |
-------------------------------------------------------
| Joe's Fish | RT-01 | 7 | 5.45 | 2020/5/20 |
-------------------------------------------------------
| Joe's Fish | CB-23 | 17 | 0.55 | 2020/5/20 |
-------------------------------------------------------
| Mack's Bugs | RT-01 | 4 | 4.45 | 2020/4/20 |
-------------------------------------------------------
| Joe's Fish | VX-28 | 1 | 1.20 | 2020/5/13 |
-------------------------------------------------------
| Karen's \/ | RT-01 | 9 | 3.45 | 2020/3/20 |
+-----------------------------------------------------+
Sheet 2: Regions
+----------------------+
| Customer | Region |
------------------------
| Joe's Fish | NA |
------------------------
| Mack's Bugs | NA |
------------------------
| Karen's \/ | EU |
+----------------------+
And my results are going in Sheet 3:
+----------------------+
| | NA | EU |
------------------------
| RT-01 | 11 | 9 |
+----------------------+
So looking at the data I made up for this question, I want to compare the number of RW-01's sold in North America to those sold in Europe. I can do it if I add an INDEX MATCH column to the end of the sales sheet, but I would have to do that every time I update the sales information.
Is there some way to do a SUMIFS like:
SUMIFS(Sheet1!$D:$D,Sheet1!$A:$A,INDEX(Sheet2!$B:$B,MATCH(Sheet1!#Current A#,Sheet2!$A:$A))=Sheet3!$B2,Sheet1!$B:$B,Sheet3!$A3)
?
I think it's difficult to do it with a SUMIFS because the columns you're matching have to be ranges, but you can certainly do it with a SUMPRODUCT and COUNTIFS:
=SUMPRODUCT(Sheet1!$C$2:$C$10*(Sheet1!$B$2:$B$10=$A2)*COUNTIFS(Sheet2!$A$2:$A$5,Sheet1!$A$2:$A$10,Sheet2!$B$2:$B$5,B$1))
I don't recommend using full-column references because it could be slow.
BTW I was assuming that there were no duplicates in Sheet2 for a particular combination of customer and region - if there were, you could use
=SUMPRODUCT(Sheet1!$C$2:$C$10*(Sheet1!$B$2:$B$10=$A2)*
(COUNTIFS(Sheet2!$A$2:$A$5,Sheet1!$A$2:$A$10,Sheet2!$B$2:$B$5,B$1)>0))
EDIT
It is worth using a dynamic version of the formula, though it is not elegant:
=SUM(Sheet1!$C2:INDEX(Sheet1!$C:$C,MATCH(2,1/(Sheet1!$C:$C<>"")))*(Sheet1!$B2:INDEX(Sheet1!$B:$B,MATCH(2,1/(Sheet1!$B:$B<>"")))=$A2)*
(COUNTIFS(Sheet2!$A$2:INDEX(Sheet2!$A:$A,MATCH(2,1/(Sheet2!$A:$A<>""))),Sheet1!$A2:INDEX(Sheet1!$A:$A,MATCH(2,1/(Sheet1!$A:$A<>""))),Sheet2!$B$2:INDEX(Sheet2!$B:$B,MATCH(2,1/(Sheet2!$B:$B<>""))),B$1)>0))
As you would need to make the match in memory I don't think it's feasible in Excel, you'll have to use a vba dictionary.
On the other hand, if the number of columns is fixed in your sales sheet, you can just format as table and add your index match in F.
When updating the sales data delete all lines as of line 3 and copy paste the update value. Excel will automatically apply the index match on all rows.

How to compare multiple HLOOKUP cases

In my sheet I have a formula using HLOOKUP to calculate a number based on the content of a cell. The content can be choosen among "OK","NOK","-".
Deliverable | CASE |Description | Value
Deliverable1 | OK | ******* | 3
Deliverable1 | NOK | ####### | 6
Deliverable1 | - | &&&&&&& | 10
Deliverable2 | OK | ******* | 4
Deliverable2 | NOK | ####### | 7
Deliverable2 | - | &&&&&&& | 9
I want then to calculate, for a given deliverable, the difference between the applied case and the case when the selection is put to "OK". I.e. if I have a -, I want to get 7.
To achieve this I have created a duplicate sheet where I force the content of the cell to be OK, and then I calculate the difference. The problem with this approach is that when using filtering or sorting the calculation is messed up.
Is there a way to avoid using the duplicate sheet?

lookup value in a non-standard table

I am trying to use VLOOKUP-like functionality on a table that I have which unfortunately doesn't have the layout that is standard for VLOOKUP function.
Layout is as below:
Dealership 1 | Dealership 2 | Dealership 3
Make | Discount 1 | Website 1 | Discount 2 | Website 2 | Discount 3 | Website 3
Hyundai | 20% | www1 | 30% | www3 | 10% | www4
BMW | 10% | www1 | 15% | www3 | 3% | www4
Honda | 20% | www1 | 50% | www3 | 70% | www4
So Normally would I would do is VLOOKUP the whole array for rows that match the make I am looking for and output the discount I am looking for. However, I want to specify which Dealership I am getting the discount from as well.
You would use the MATCH as your third Criterion:
=VLOOKUP(I2,$A:$G,MATCH(J2,$1:$1,0),FALSE)
The MATCH() returns the column in which the Dealership is found. And uses that in the VLOOKUP to denote in which column the discount is found.
You can use the INDEX and MATCH combination to get a value in a 2D range
The formula I used here was
=INDEX($B$2:$G$4,MATCH($B$7,$A$2:$A$4,0),MATCH("Discount "&$B$8,$B$1:$G$1,0))

How to find duplicate adjacent cells in Excel

I have 2 columns in Excel (like below) and I would like to identify (conditionally format) any rows that are exactly the same.
As you can see 326.001 1,000 HOUR are identical for the first 3 rows, I would like to highlight or mark these rows so I can see that they are not unique.
+---------+------------+
| ID | INTERVAL |
+---------+------------+
| 326.001 | 1,000 HOUR |
| 326.001 | 1,000 HOUR |
| 326.001 | 1,000 HOUR |
| 326.001 | 3,000 HOUR |
| 326.002 | 1 MONTH |
| 326.002 | 1 YEAR |
| 326.002 | 5 YEAR |
| 326.002 | 500 HOUR |
| 326.002 | 500 HOUR |
| 326.002 | 500 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 3,000 HOUR |
| 326.009 | 3 MONTH |
| 326.009 | 1 YEAR |
| 326.01 | 3 MONTH |
+---------+------------+
I would add a third column: EqualityTest, with a formula such as:
=AND([#ID]=A5,[#INTERVAL]=B5)
This assumes the data is sorted.
The above formula is for row 5, with ID and Interval in columns A and B. Copy-Paste the formula down, and apply conditional formatting to highlight False for unique values.
qroberts,
I'm not clear on your question.
If you're actually attempting to remove duplicate rows, Excel offers that as a function on the basic ribbon bar for the "Data" ribbon: the button (!) is "Remove Duplicates" in the "Data Tools" section on the "Data" ribbon.
If, instead, you are looking for a highlighter which will identify duplicates, things are a bit more complicated, as you need a macro which will find duplicates and then turn on some form of formatting/highlighting (I suggest formatting a background color).
For a macro which will highlight duplicates, we need to hear a bit more to understand your needs. If you have two different sets of duplicates, do you want them highlighted to different colors? If the number of duplicate sets
gets large, this could be a problem.
As another poster has noted, it also matters whether your candidate set is sorted. A full range search for duplicates would be an interesting bit of coding.
So use COUNTIFS():
=COUNTIFS($A$2:$A$10000,$A2,$B$2:$B$10000,$B2)>0
It will return true for any that has duplicates in both columns. This formula does not care if the data is sorted or not.

Excel search value from whatever row and if found on another row replace that row with the value in the first row

What I am Trying to do is
lets say I have a excel sheet with
rows
ProductNo | Product | Sku | Price | Image | Thumb
25 | Shirt Blue | 4251 | $10 | shirt.jpg | shirtthumb.jpg
2 | Shirt Green | 4581 | $17 | green.jpg | greenthumb.jpg
8 | Shirt Black | 4561 | $15 | black.jpg | blackthumb.jpg
and just in different rows or on another excel sheet
ProductNo | Product | Sku | Price | Image | Thumb
25 | Shirt Blue | 4251 | $52 | |
2 | Shirt Green | 4581 | $42 | |
8 | Shirt Black | 4561 | $65 | |
How can i change the first table to update if the the second table or sheet columns data is different on specified columns and if the cells are empty forget about them ignore them and just replace the values from the second table onto the first
Final would be
ProductNo | Product | Sku | Price | Image | Thumb
25 | Shirt Blue | 4251 | $52 | shirt.jpg | shirtthumb.jpg
2 | Shirt Green | 4581 | $42 | green.jpg | greenthumb.jpg
8 | Shirt Black | 4561 | $65 | black.jpg | blackthumb.jpg
I have tried a couple of excel functions but they do not work since i have so many products to be doing cell additions
I tried doing in Vl but got confused and macro i dont even know what it is
Im open to whatever visual, functions just as long as i can perform the task
if anybody know hos let me know
Thank You
in stead of having the fixed values I propose you use a permanent formula in the specified columns.
Now to do this I would use a VLOOKUP() function. I am assuming that your ProductNo is the element that never changes therefore all the other columns will get a VLOOKUP() function.
Now if I understand correctly you MIGHT have an update in the 2nd table for the 1st table, but any empty cells in the 2nd table should be ignored.
I am also assuming you wish to see when an element will change because of the update therefore I propose the following:
In the first table add for the block of columns elements that might need an update: 2 blocks of columns, the first with the result of combining (the COMB-block) and the second with lookups from the 2nd table (the LOOKUP-block). For convenience of explaining I put the two tables in the same workbook on the sheets called table1 and table2
ProductNo | Product | Sku | Price | Image | Thumb | Product_comb | Sku_comb | Price_comb | Image_comb | Thumb_comb | Product_lookup | Sku_lookup | Price_lookup | Image_lookup | Thumb_lookup
Now start with formulas in the LOOKUP-block, use VLOOKUP(), such as this one for the *Product_vlookup* column:
=IFERROR(VLOOKUP($A2,table2!$A:B,COLUMNS(table2!$A:B),FALSE),"")
The IFERROR is for the case the product in table1 cannot be found in table2
For the formulas in the COMB-block the following will prefer the table 2 result over the table 1 result. As VLOOKUP of a matching ProductNo with an empty Element (for example for the Image) will result in a 0 (zero) returned all zeroes are regarded false lookup results as well. This is the script for the *Product_comb* column:
=IF(OR(ISBLANK(L2),L2=0),B2,L2)
As a final step to identify the products that changed you can either add a column that compared the original value with the _comb value:
=AND(B2=G2,C2=H2,D2=I2,E2=J2,F2=K2) (this returns true for no changed columns and false for any changed column)
Or use conditional formatting on each element separately or on the combination as the AND() formula shows.
As a final step in your process of updating you could copy all records from the COMB-block and paste it over the original elements.
If you have any further questions please ask.

Resources