Index/Sumproduct with 3 criteria - excel

I am trying to lookup a value from another table based on a reference table.
See below my data sample:
SHEET 1 ("CalculationLiability"):
SHEET 2 ("KeyMetrics"):
In sheet 1, cell G7 I am trying to look up the value from Sheet 2 based on 3 criteria (supplier unique ID, type and season) I tried the following formula, but it is returning a #REF error.
=INDEX(KeyMetrics!$F$6:$AS$100,
SUMPRODUCT((KeyMetrics!$D$6:$D$39=CalculationLiability!$D7)*
(KeyMetrics!$E$6:$E$39=CalculationLiability!$G$6)*
(KeyMetrics!$F$5:$AS$5=CalculationLiability!$E7)))
Anyone knows what I am doing wrong here? I can get it to work for two criteria, but for three criteria it doesn't work. Any help or push into the right direction is much appreciated!

The Index uses a multi column, multi row reference. That means that you need two additional arguments, one argument for row, and another for column.
Your formula currently only provides one additional argument. When you step through the formula with the Evaluate Formula tool you can see that in the last step.
You can use an Index with two Match functions. The first one to find the row, the second one to find the column.
=INDEX(KeyMetrics!$F$6:$AS$100,
MATCH($D7&$G$6,INDEX(KeyMetrics!$D$6:$D$100&KeyMetrics!$E$6:$E$100,0),0),
MATCH(CalculationLiability!E7,KeyMetrics!$F$5:$AS$5))
You can also use Sumproduct, but in that case, don't use Index.
=SUMPRODUCT(KeyMetrics!$F$6:$AS$39,
(KeyMetrics!$D$6:$D$39=CalculationLiability!$D7)*
(KeyMetrics!$E$6:$E$39=CalculationLiability!$G$6)*
(KeyMetrics!$F$5:$AS$5=CalculationLiability!$E7))

Related

Excel - Retrieving a cell based off of multiple criteria

I am attempting to return the value of a cell from within a different sheet based upon two cell values in the second sheet.
As an example the Main and Second sheet have three columns each (Item, Code, Number), the difference being that the second sheet has only one row and two drop down lists that are populated with the Item(s) and Code(s) (from the Main sheet - i.e like a database table). From within the Second sheet I would like the Number to be returned from the main sheet, once the Item and Code had been selected from the drop down lists on the Second sheet.
Unfortunately I'm unsure as how to do this based off of multiple criteria. As far as I'm aware VLOOKUP only used one criteria over a range. I've attempted the following below which is accepted by Excel as a valid formula, however it doesn't return the correct value.
{=SUMPRODUCT((Main!A:A='Second'!A7) * (Main!C:C='Second'!E2) * (Main!G:G))}
I've interpreted the above as the first two sets of brackets being the range and condition to match and the last set being the range of values to return from. Is this a correct assumption and is this the correct use of that function?
Are there any other functions I could use?
Thank you, I have very little experience with Excel!
Have you taken a look at the magic INDEX combined with MATCH, and perhaps MATCH again?
INDEX returns the contents of a cell from a table provided a row and a column. Usage:
=INDEX([table to look in]; [COLUMN index]; [ROW index])
MATCH returns the indexes that match a criteria in the table. Usage:
=MATCH([Criteria];[table to look in])
And you can nest one inside the other the following way:
=INDEX([table to look for in];MATCH([Criteria];[Table to look for the particular Row]);[COLUMN, or a second MATCH to find the right column])
Or even combine a couple of MATCH as in
=INDEX([table to look for in];AND(MATCH(1);MATCH(2)); [Column to look for, or MATCH to look for in column])
Which I think is what you want.
If you need a SUM of something (as you used a SUM function before), just nest it inside the proper SUM function

Test whether a value in a cell matches another value in an array, and do an action if a match is found

I am trying to create a formula that will look at a cell and test the value in that cell against an array or multiple arrays of cells, and if a match is found, take another action like calculate a mathematical formula.
Really the action taken afterwards is not the issue, just used as a reference of what I ultimately intend to do with the formula. The biggest hurdle I am having is the first part of the formula where I need to test values.
I need to test the employee ID's in column W against the same employee ID's located in the "doors" columns and see if there is a match, and if there is, do another action.
Formulas I have tried, though I really don't know what I should be doing here:
{=IF(W5=T4:T7,"true")}
{=IF(OR(F4:F7,H4:H7,J4:J7,L4:L7,N4:N7,P4:P7,R4:R7,T4:T7)=W6,"True")}
Any help would be appreciated. Please let me know if I need to elaborate.
Use MATCH for one column:
=IF(ISNUMBER(MATCH(W6,$T$4:$T$7)),X6/5000*1000000,0)
For multiple columns:
=IF(ISNUMBER(AGGREGATE(15,7,ROW($B$4$:$T$7)/($B$4$:$T$7=W6),1)),X6/5000*1000000,0)

Excel Formula Vlookup the value by referring Row and Column

In the sheet1 i have a table called working days of the countries as shown in the below image.
In the Sheet2 i have 10 columns in that based on the country and month by referring the this table i am trying to populate the values, When i tried doing by Vlookup the first row alone getting populated, but in the second row the header from F1:T1 is getting changed to F2:T2 so rest of the cells showing as #NA.
Anyone can you please give a solution for my issue. Here is the formula i have used.
=VLOOKUP(I1,Sheet1!F2:T7,MATCH(Sheet2!M1,Sheet1!F1:T1,0))
Thanks in Advance.
You are missing the symbol $ to lock the ranges, and the false condition to match exact values in the VLOOKUP.
It should be like:
=VLOOKUP(I1,Sheet1!$F$2:$T$7,MATCH(M1,Sheet1!$F$1:$T$1,0),0)
Or instead of VLOOKUP use HLOOKUP like:
=HLOOKUP(M1,Sheet1!$F$1:$T$7,MATCH(I1,Sheet1!$F$2:$F$7,0),0)
In general, combining the INDEX and MATCH functions is a superior option to VLOOKUP. For example, =INDEX(Sheet1!F:F,MATCH(Sheet2!M1,Sheet1!F1:T1,0)). This allows you to go left-to-right or right-to-left as well.
Snip for Index Match functions Using Vlookup won't work here because in the 2nd table you are repeating the country, unlike the first table. Use a combination of index match function, this is little trickier than the vlookup but it will fulfill your requirements.
Since I don't have the exact table you shared so I created a table on my end and sharing the snip here.

Excel - Conditional row from an array to COUNTIF from VLOOKUP

I don't know if I'm going about this the wrong way but it seems like it should be simple. Column A has a list of Names. Along each row is several "W"'s. Another separate field has a drop down representing Column A names. I want to count the number of "W"'s in a row corresponding to what name I select. I've tried using VLOOKUP and COUNTIF but I can't figure out how to select the entire array and then single out the one row that matches my selected name. I can get it working with a bunch of IF statements but thats far too time consuming as I'm manually matching the name to the row (and it isn't future proof).
There are a few ways to first 'narrow in' on the row you're looking for, after which point you can use a simple COUNTIFS to check the number of W's in that row.
One method would be to simply use INDIRECT, and create the row reference on the fly, like so [assumes your search cell is C1]:
=COUNTIFS(INDIRECT(MATCH(C1,A:A,0)&":"&MATCH(C1,A:A,0)),"W")
This first uses MATCH to find the appropriate row, and then builds a reference to that row [like "24:24"], which becomes the row that INDIRECT passes to COUNTIFS, which counts that row for W's.
For only one use of INDIRECT, the high computing costs of INDIRECT should not be an issue.
Another method would be to point out the full possible box that data could be contained in [let's assume that at most only column H would be used], and then use INDEX to give us the appropriate row number, like so:
=COUNTIFS(INDEX(A:H,MATCH(C1,A:A,0)),0,"W")
This again uses MATCH to find the row which contains the value found in C1 within column A. Then it takes the full possible box from INDEX, and returns all columns from the particular row [note that telling index to return 0 for the column # actually returns all columns instead].
Other methods would be possible [for example OFFSET], but I believe these two show the principle fairly well.
You could use the "Helper" Column method:
In the helper column:
=COUNTIF(B2:H2,"W")
Then use SUMIF() in the totals column:
=SUMIF($A$2:$A$9,K2,$I$2:$I$9)

DGET NUM error with criteria

DGET functions in my spreadsheet have a problem with criteria strings having the same starting characters. This is a problem. How do I resolve this?
Ex: =DGET(database, field, criterion1)
The database contains entries for criteria values of "ABC" and "ABC_123", say.
If I call DGET(database, field, "ABC"), it results in a NUM error. What do I do about this? I cannot change the spreadsheet from which the criteria values are extracted for input into the DGET function - for example I can't add columns, etc. I may be able to make some limited changes to the database entries.
I think you will need two changes (though due to #NUM error instead of #VALUE maybe just the first). To do an exact match with DGET you need to preface your criteria with =. So instead of "ABC" you would need "=ABC". The final parameter of the DGET function does not want a single string value. As noted on the MSDN page:
You can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label in which you specify a condition for the column.
I think that third parameter should be a range of two cells with your criteria field name in the first cell and your criteria value =ABC below it. You can place this range on another worksheet if you like to stage it with the = as you pull it in from the other spreadsheet.
For example in my testing I am using the formula =DGET($G$1:$I$4,"Field 3",A1:A2) where A1 is Field 2 and A2 is ="=ABC" and columns headers are in G1:I1. This returns the value in column Field 3 when column Field 2 is ABC exactly.
DGET is touchy and not something I usually recommend so make extra sure you run key test cases when making revisions and verify this returns exactly what you want.

Resources