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.
Related
I am trying to extract the value like what we can do with vlookup, but in this case it has to coincide with the value on two different columns.
I want to extract the values which match with the two columns in yellow.
Sheet1 (where I am looking for coincidence of two values)
For that I am using the formula IF(COUNTIFS(....)=1;"value that I am looking for"; no match)
But I donĀ“t know what to put on "value that I am looking for", because if I add directly the cell from the row, it delivers directly a wrong value.
Sheet2 (where I want to add these two values, and formula that I am testing)
If you have O365, you can use a combination of INDEX and FILTER function to do this
=INDEX(FILTER('Sheet 1'!$A$2:$E$10,('Sheet 1'!$A$2:$A$10='Sheet 2'!$B192)*('Sheet 1'!$E$2:$E$10='Sheet 2'!$C192),""),1,2)
You need to update the 'Sheet 1'!$A$2:$E$10 range according to your data.
Also note that this will return the 1st match of both Partner object and Value in Obj. Crcy row, even if there are multiple matches
Edit:
As suggested by #P.b in the comments below, you can also use:
=#FILTER('Sheet 1'!$B$2:$B$10,('Sheet 1'!$A$2:$A$10='Sheet 2'!$B192)*('Sheet 1'!$E$2:$E$10='Sheet 2'!$C192),"")
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))
This pictures shows my table and formula's yield
I have used following formula to extract result from a table.
Its working perfectly fine but I am hoping to level up my understanding of Excel formulas.
The trouble is that I use IF in Excel way to often.
what I wanted to know is if its possible to use a different approach, something that can work similar to if but is perhaps more sophisticated.
=IF(OR(J2="08L",J2="08R"),IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$34,0)),"LAM",IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$35:$E$35,0)),"West",IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$36:$G$36,0)),"East",IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$37,0)),"SFD",NA())))),0)
I very much appreciate any help.
Now that there is an example, I think this is a good question. You've recognised that your formula is fairly messy and also can't be easily expanded if there are more routes.
The problem is that Excel is very good for searching for a value in a single row or column, but not as good for searching for a value in a block of data.
You can simplify this problem by creating an additional column that has each entire route in a single cell. You can do this just by concatenating values. In your example, use column H:
=B2&" "&C2&" "&D2&" "&E2&" "&F2&" "&G2
This will create a string with the entire route in a single cell. Spaces are added in between each part of the route to make sure you don't accidentally create a sequences of letters that matches part of another route. It doesn't matter if there are blank cells, there will just be some extra spaces at the end which doesn't matter. Fill this down the column to get the entire path for each route in a single cell.
Then, you can create a formula that tries to find the 3 letters anywhere in any of the full routes.
=INDEX($A$2:$A$5,MATCH("*"&left(I2,3)&"*",$H$2:$H$5,0))
This formula is basically a deconstructed vlookup. It determines where the 3 characters can be found in column H, then gives back the corresponding value from column A.
The MATCH function tries to find the left 3 characters of I2 in column H. The MATCH function normally tries to find a complete exact match (with the last parameter being equal to 0), but we can just add wildcards to the search value. The MATCH function then returns the index of the range where it was found. I.e., if it was found in the 2nd cell of the range H2:H5, it returns the number 2.
The INDEX function then just gets a value from a range based on an index. In this case, it will get the 2nd value from range A2:A5.
I am working on a statistical model where we use sumproduct to generate forecast values by multiplying coefficients in one table with variables in another. Right now it is being done manually and that is taking time. I would like to automate it but I'm not able to figure this out.
We are using concatenate to identify different rows to use for vlookup. The variable columns are the same in number for both tables. I need to multiply each variable cell respectively in both tables and sum them, hence sumproduct.
this is what I am trying to do
Forecast model 1 sales for product A in phones in USA = sumproduct([variables by year from table 1 for USA for phones], [Variables for USA phone product A model 1 from table 2] )
I hope someone can help me.
Proof of Concept
You will need to update the references to suit your spreadsheet table locations.
In cell E21 use the following and copy right and down as required:
=SUMPRODUCT(INDEX($G$3:$I$12,MATCH($B21&$A21&$C21,$A$3:$A$12,0),0),INDEX($F$15:$H$18,MATCH($A21&$C21&$D21&MID(E$20,16,1),$A$15:$A$18,0),0))
This process was simplified because you had a unique ID tag on each of the previous two tables that could be built from the information in the third table. If you ever get into double digit forecast models the MID() function part of the formula will need to be modified. The 16 in the mid function refers to the character location of the number in the forecast model sales header name in Table 3. As such you either need to keep that header format exactly the same or modify the position of the number in the MID() function.
UPDATE 1
Explanation of Formulas
The following formulas were used in this solution:
SUMPRODUCT
INDEX
MATCH
MID
Concatenate
I will start with the assumption that you already understand sumproduct() as you were already using it before you ran into your problem. One thing to note about sumproduct is that it causes array like calculation to occur on the portion within it brackets. In this case we fed it two ranges of equal size. The difficult part was more an issue of determining those ranges.
Using your ID columns as a lookup row we used the match() function to determine which row to use. For the first set of variables we used the following to determine which row to look in:
=MATCH($B21&$A21&$C21,$A$3:$A$12,0)
Match is made up of three arguments inside the brackets:
MATCH(what to look for, where to look, type of match)
What we need to look for in table is a concatenation of various cells in Table 3 to build the ID in Table 1. It could have been written using the full formula:
=CONCATENATE($B21,$A21,$C21)
but the short form using & was used instead:
=$B21&$A21&$C21
Once we had what to look for we needed the range of where to look and supplied the ID column from table 1:
$A$3:$A$12
This now leaves the third and final argument of what type of search to perform. An exact match seemed to be the most appropriate match to perform so the value of 0 was supplied. What match returns is the row within the supplied range. It is relative to the range supplied and not the actual row in the spreadsheet. If it cannot make a match it will return an error instead of a row number.
Now that we know what row we want, we can use this information with the INDEX() function. The INDEX() function is made up of 3 arguments as well with the third argument being optional depending on if a 1D or 2D range is being indexed:
INDEX(Range to work with, 2D Row or 1D Position reference, 2D Column reference)
IN the case we are dealing with for the first table, the range to work with was your list of variables:
$G$3:$I$12
This is a 2D range. As such we need to tell INDEX() both what Row to look in as well as which Columns to look in. For the row to look in, we used the previously discussed MATCH() function. Since we want all columns and not just a specific column we use the value of 0. If Match returns an error, or if a number greater than the number of rows or columns selected is supplied, INDEX() will return an error. Based on the information discussed, the index function would look like:
=INDEX($G$3:$I$12,MATCH($B21&$A21&$C21,$A$3:$A$12,0),0)
You can try entering the above in a cell but it will give you an error. if you select three adjacent cells in the same row and use CONTROL+SHIFT+ENTER when entering the formula, Excel will add {} around the formula and it will be an array formula and should show you the three variables being used.
The same process as described above can be used for determining the second range of variable from Table 2. The only difference here is that the forecast model number was not in a column of its own but instead in the header row surrounded by text. As such the MID() function needed to be used to go into the header row, bypass the surrounding text and pull the model number out so it could be used as part of the CONCATENATION() used for the "what to look for" in MATCH():
=MID(E$20,16,1)
The MID() function work again with three arguments:
MID(Text to look in, which character to start at, how many characters to pull)
So in this case we are looking at the header in E20. Note the lock $ on the row number so the formula is always looking in row 20 no matter how far down it gets copied. It is then going to the 16th character. In this case the character "1" and pulling 1 character. If the header had just been 1 and 2, there would be no need for the MID function and the cell (with proper lock) could have been used.
I have a data set that I want to return an indexed column using two values: a year and a name. Both these values are formatted to general (I also tried text) in my spreadsheet.
In one work sheet I have a like of people:
On the other, I have a table of Years, Names, and a number
I am trying to do a lookup on the joined year and name and return the given number in the second table. For instance 2013Andrew McCutchen would return 8.2, and 2014Andrew McCutchen would return 6.8.
Currently, I only get the #N/a value with the following"
=INDEX('2006 Results'!C2:C556,MATCH($J$1&C3,'2006 Results'!$A$2&$B$556,0))
But, I know a certain value is in the table though because I have tested with an if statement to make sure my spelling is correct. Any guidance would be much appreciated.
I would add a column to the left of the year column as column A to contain the following formula in cell A2 which refers to the year and name column:
=$B2&$C2
You can then use this column in a VLOOKUP formula on the people sheet. Cell J3 would read as follows. Copy this to all cells in the table body.
=VLOOKUP(J$1&$C3,'TheYearSheet'!$A$1:$D$556,4,false)
Job done.
In your match expression, you are comparing one concatenated value $J$1&C3 to another single concatenated value '2006 Results'!$A$2&$B$556. Match expects that second parameter to be a range rather than a single value.
In cases like this, where multiple criteria are required, I prefer to use sumifs rather than index-match, even though the intention is to return a single value. I think =SUMIFS('2006 Results'!$C:$C,'2006 Results'!$A:$A,j$1,'2006 Results'!$B:$B,$c3) will give what you need and should correctly copy to the other cells in that table.