excel - Combine VLOOKUP with Datevalue function - excel

Is it possible to use the DATEVALUE function inside a vlookup?
I am trying to lookup a date in a separate sheet but the date is formatted as string so I'd like to use the DATEVALUE function to convert it.
I have played around with putting the datevalue in a few different positions within the vlookup but no luck.
Any help would be greatly appreciated!

Here/screenshot(s) refer -
Of course you can- you just need to know how vlookup works and manipulate accordingly - I provide the solution you have specifically requested, together with 2 other possible ways of looking up without 'parsing to date format' in first instance:
Revision : see here for how to input array formula for different versions of Excel - these are otherwise valid for both 2010/Office 365 compatible version of Excel.
1] Vlookup
=VLOOKUP(G4,IFERROR(DATEVALUE(C4:D6),D4:D6),2,0)
Unlike other lookup functions (e.g. M2-M3, offset etc.) vlookup cannot be used as a reference itself - it requires the entire range to be included and then 'pivots' on the first column. This is why you can lookup datevalue of the single column which contains valid text formatted dates, but once you reference a larger range, datevalue(larger range) will return errors for any value in that range which cannot be converted to a date. Hence the iferror component.
I suspect the fundamental goal is to return the cell corresponding to the datevalue of the text you're looking up - you couldn't be fussed whether it's a vlookup or any other form of lookup. Here are two other methods to achieve this objective:
2] Sum
=SUM(1*(DATEVALUE(C4:C6)=G4)*(D4:D6))
(Uncommon, albeit parsimonious lookup tool)
3] Index
=INDEX(D4:D6,MATCH(G4,DATEVALUE(C4:C6),0))
Closing remarks
Index is typically preferable to vlookup, given the advantage of being able to be used as a reference itself (e.g. you could have offset(index<>) but not offset(vlookup<>)) - this is why index can lookup columns to the left/right of the lookup column (vlookup works to the right only). The only advantage vlookup() has is the approximate search function (final parameter = True to enable). Xlookup() is more versatile; offset() is another 'special / honorary' mention which I have not provided examples for - but also feasible (albeit the latter is has negative stigma associated due to its volatile nature - but that's for another post!)

Related

excel: Look up value within cell from list of values in other range [duplicate]

Currently I have a set of cells, and each has, among useless information, a unique identifier. I also have a list of these unique identifiers, as well as what value each identifier corresponds to.
What I would like to do is find which, if any, identifier a cell contains, and then output the corresponding value, below is an example:
http://i.stack.imgur.com/97aKI.png
So where the cell contains "ADC", I would like excel to find where ADC comes up in the reference array, and then return the corresponding value.
If this can be done with a formula or a macro, either would be great. I have tried fiddling with index, match, and search, in various combinations, but nothing seems to be working. I have found creating a massive if statement to be impractical as there are about 70 unique values to search for.
Any suggestions would be welcome!
edit: I was recommended to use vlookup, but I am not looking for an identical match, but instead for a specific value contained within a string. If vlookup does have this functionality then could somebody show me how to put this into practice with my specific example?
One method of a 'reverse-wildcard' lookup can be achieved is with the newer AGGREGATE¹ function. This function can produce cyclic calculation and has an option (e.g. 6) to discard errors. Use this to produce a row number on the match to the cross-reference table with the INDEX function returning the actual value.
      
The formula in B3 is,
=INDEX(F$3:F$5, AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&E$3:E$5&"*", A3, 0)), 1))
Note that ROW(1:3) is the position within F3:F5, not the actual row number on the worksheet. I've also scrambled the Find and Insert values in your original cross-reference table to avoid the perception of an associative lookup match.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Is there any way to use a wildcard in order to count dates?

Is there a way to use a wildcard to count the partial string of a date?
In my spreadsheet, I want to use the COUNTIF function to count a certain date. However, the date value also contains the time.
Example: "12/06/2017 17:35:12"
I only want to include "12/06/2017"
This is the formula I have: =COUNTIF(Pivot_Data[Created Date],"*12/06/2017*")
If I recall correctly, you must use the "&" concatenation operator on the wildcard symbol instead of including it with the rest of your string. This is specific to the countif and sumif functions:
=COUNTIF(Pivot_Data[Created Date],"*"&"12/06/2017"&"*")
EDIT: Here is a solution for date formats instead of text formats:
=COUNTIFS(Pivot_Data[Created Date],">"&DATEVALUE("12/06/2017"),Pivot_Data[Created Date],"<"&(DATEVALUE("12/06/2017")+1) )
This works because the date is represented as an unique integer in Excel's date encoding, with the time as a decimal value.
Place * either side of the date.E.g. =COUNTIF(E9,"*12/06/2017*")
This is a wildcard match. Adjust range according to needs.
Instead of searching for a specific text, I would just check if the date is the same as Excel's built in serial number. Also I prefer SUMPRODUCT over COUNTIF.
Something like:
= SUMPRODUCT((FLOOR(Pivot_Data[Created Date],1)=DATE(2017,12,6))+0)
The FLOOR function (in this case) effectively just takes the date and removes any reference to what time it is on that date.
I think this way is better because it doesn't rely on the cell being a specific text format.
See below, I used this formula but replaced Pivot_Data[Created Date] with A1:A5 just to demonstrate that this formula works with sample data. As expected, the formula returns a value of 2 because the data contains two dates on 12/6/2017. Notice how it doesn't care what time it is.

Index Match with WildCards - Excel [duplicate]

Currently I have a set of cells, and each has, among useless information, a unique identifier. I also have a list of these unique identifiers, as well as what value each identifier corresponds to.
What I would like to do is find which, if any, identifier a cell contains, and then output the corresponding value, below is an example:
http://i.stack.imgur.com/97aKI.png
So where the cell contains "ADC", I would like excel to find where ADC comes up in the reference array, and then return the corresponding value.
If this can be done with a formula or a macro, either would be great. I have tried fiddling with index, match, and search, in various combinations, but nothing seems to be working. I have found creating a massive if statement to be impractical as there are about 70 unique values to search for.
Any suggestions would be welcome!
edit: I was recommended to use vlookup, but I am not looking for an identical match, but instead for a specific value contained within a string. If vlookup does have this functionality then could somebody show me how to put this into practice with my specific example?
One method of a 'reverse-wildcard' lookup can be achieved is with the newer AGGREGATE¹ function. This function can produce cyclic calculation and has an option (e.g. 6) to discard errors. Use this to produce a row number on the match to the cross-reference table with the INDEX function returning the actual value.
      
The formula in B3 is,
=INDEX(F$3:F$5, AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&E$3:E$5&"*", A3, 0)), 1))
Note that ROW(1:3) is the position within F3:F5, not the actual row number on the worksheet. I've also scrambled the Find and Insert values in your original cross-reference table to avoid the perception of an associative lookup match.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Using SUMIFS with multiple AND OR conditions

I would like to create a succinct Excel formula that SUMS a column based on a set of AND conditions, plus a set of OR conditions.
My Excel table contains the following data and I used defined names for the columns.
Quote_Value (Worksheet!$A:$A) holds an accounting value.
Days_To_Close (Worksheet!$B:$B) contains a formula that results in a number.
Salesman (Worksheet!$C:$C) contains text and is a name.
Quote_Month (Worksheet!$D:$D) contains a formula (=TEXT(Worksheet!$E:$E,"mmm-yy"))to convert a date/time number from another column into a text based month reference.
I want to SUM Quote_Value if Salesman equals JBloggs and Days_To_Close is equal to or less than 90 and Quote_Month is equal to one of the following (Oct-13, Nov-13, or Dec-13).
At the moment, I've got this to work but it includes a lot of repetition, which I don't think I need.
=SUM(SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Oct-13")+SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Nov-13")+SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Dec-13"))
What I'd like to do is something more like the following but I can't work out the correct syntax:
=SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,OR(Quote_Month="Oct-13",Quote_Month="Nov-13",Quote_Month="Dec-13"))
That formula doesn't error, it just returns a 0 value. Yet if I manually examine the data, that's not correct. I even tried using TRIM(Quote_Month) to make sure that spaces hadn't crept into the data but the fact that my extended SUM formula works indicates that the data is OK and that it's a syntax issue. Can anybody steer me in the right direction?
You can use SUMIFS like this
=SUM(SUMIFS(Quote_Value,Salesman,"JBloggs",Days_To_Close,"<=90",Quote_Month,{"Oct-13","Nov-13","Dec-13"}))
The SUMIFS function will return an "array" of 3 values (one total each for "Oct-13", "Nov-13" and "Dec-13"), so you need SUM to sum that array and give you the final result.
Be careful with this syntax, you can only have at most two criteria within the formula with "OR" conditions...and if there are two then in one you must separate the criteria with commas, in the other with semi-colons.
If you need more you might use SUMPRODUCT with MATCH, e.g. in your case
=SUMPRODUCT(Quote_Value,(Salesman="JBloggs")*(Days_To_Close<=90)*ISNUMBER(MATCH(Quote_Month,{"Oct-13","Nov-13","Dec-13"},0)))
In that version you can add any number of "OR" criteria using ISNUMBER/MATCH
You can use DSUM, which will be more flexible. Like if you want to change the name of Salesman or the Quote Month, you need not change the formula, but only some criteria cells. Please see the link below for details...Even the criteria can be formula to copied from other sheets
http://office.microsoft.com/en-us/excel-help/dsum-function-HP010342460.aspx?CTT=1
You might consider referencing the actual date/time in the source column for Quote_Month, then you could transform your OR into a couple of ANDs, something like (assuing the date's in something I've chosen to call Quote_Date)
=SUMIFS(Quote_Value,"<=90",Quote_Date,">="&DATE(2013,11,1),Quote_Date,"<="&DATE(2013,12,31),Salesman,"=JBloggs",Days_To_Close)
(I moved the interesting conditions to the front).
This approach works here because that "OR" condition is actually specifying a date range - it might not work in other cases.
Quote_Month (Worksheet!$D:$D) contains a formula (=TEXT(Worksheet!$E:$E,"mmm-yy"))to convert a date/time number from another column into a text based month reference.
You can use OR by adding + in Sumproduct. See this
=SUMPRODUCT((Quote_Value)*(Salesman="JBloggs")*(Days_To_Close<=90)*((Quote_Month="Cond1")+(Quote_Month="Cond2")+(Quote_Month="Cond3")))
ScreenShot
Speed
SUMPRODUCT is faster than SUM arrays, i.e. having {} arrays in the SUM function. SUMIFS is 30% faster than SUMPRODUCT.
{SUM(SUMIFS({}))} vs SUMPRODUCT(SUMIFS({})) both works fine, but SUMPRODUCT feels a bit easier to write without the CTRL-SHIFT-ENTER to create the {}.
Preference
I personally prefer writing SUMPRODUCT(--(ISNUMBER(MATCH(...)))) over SUMPRODUCT(SUMIFS({})) for multiple criteria.
However, if you have a drop-down menu where you want to select specific characteristics or all, SUMPRODUCT(SUMIFS()), is the only way to go. (as for selecting "all", the value should enter in "<>" + "Whatever word you want as long as it's not part of the specific characteristics".
In order to get the formula to work place the cursor inside the formula and press ctr+shift+enter and then it will work!
With the following, it is easy to link the Cell address...
=SUM(SUMIFS(FAGLL03!$I$4:$I$1048576,FAGLL03!$A$4:$A$1048576,">="&INDIRECT("A"&ROW()),FAGLL03!$A$4:$A$1048576,"<="&INDIRECT("B"&ROW()),FAGLL03!$Q$4:$Q$1048576,E$2))
Can use address / substitute / Column functions as required to use Cell addresses in full DYNAMIC.

reversing rows in excel formulas

(A) SumProduct( A1:A3,B1:B3) == A1*B1 + A2*B2 + A3*B3
Instead, what I'm after is
(B) SumProduct( A1:A3, Reverse(B1:B3)) == A1*B3 + A2*B2 + A3*B1
Is there a clean way to achieve this in excel 2003 / excel 2007 ? The natural ordering of these values is A1->A3 and B1->B3, so reversing the meanings of the cells is unsatisfactory; but creating a reversed copy of B1:B3 elsewhere in the worksheet seems clumsy.
Check the topic "Transposing A List Of Data" in http://www.cpearson.com/EXCEL/lists.htm
I chanced upon this question because I was trying to find an answer to this very question, in particular a solution to be used with SUMPRODUCT.
Previous post with link was useful, and the following has been devised. Please, note that for simplicity and clarity original references have been changed to make spreadsheet formulas easier to understand. Necessary changes can be achieved by using INDIRECT and R1C1 reference style if reversal needs to be applied to columns (INDIRECT, COLUMN and COLUMNS function documentation would prove useful).
In Excel (checked in Excel 2010), the formula that SUMPRODUCTs an array in A6:A8 with the reversal of the array in B6:B8 (let's say B8:B6) could be
=SUMPRODUCT(A6:A8,N(OFFSET(B6:B8,ROWS(B6:B8)-ROW(INDIRECT("A1:A"& ROWS(B6:B8))),0)))
The reversing part for Excel is N(OFFSET(B6:B8,ROWS(B6:B8)-ROW(INDIRECT("A1:A"& ROWS(B6:B8))),0)), it can also be used as a multi-cell array formula (ctrl-shift-enter) anywhere - the array to be reversed is in B6:B8.
Brief explanation: N() is necessary to convert the references returned by OFFSET into an array of values that can be used inside SUMPRODUCT. (OFFSET without N() render the formula inoperative within SUMPRODUCT, and it converts most non numbers into 0, as expected it converts TRUE to 1.)
OFFSET takes the array on the spreadsheet and puts the values in reverse order. (In this case, offset original at 3-1=2 goes new array position 0, 3-2=1 goes to 1, and finally 3-3=0 goes to 2.) ROW() function creates an array of consecutive numbers that can be subtracted from the length of the total array [please note, no final S, and A1:A3 has been used to obtain {1,2,...}, up to the number of rows in the original array/range.]
This formula does NOT work in OpenOffice/LibreOffice spreadsheet application. But INDEX can with an analogue approach becoming even more flexible.
OpenOffice/LibreOffice can use the same approach but with the INDEX function. OpenOffice/LibreOffice solution does not work in Excel as Excel does not accept arrays in INDEX's row_num/col_num (any array as argument there becomes the single top element of the array).
In OpenOffice/LibreOffice (checked in Apache OpenOffice 4), the formula that SUMPRODUCTs an array in A6:A8 with the reversal of the array in B6:B8 could be
=SUMPRODUCT(A6:A8,INDEX(B6:B8,1+ROWS(B6:B8)-ROW(INDIRECT("A1:A"& ROWS(B6:B8))),0))
The reversing part for OpenOffice is INDEX(B6:B8,1+ROWS(B6:B8)-ROW(INDIRECT("A1:A"& ROWS(B6:B8))),0), it can also be used as a multi-cell array formula (ctrl-shift-enter) anywhere - the array to be reversed is in B6:B8.
Excel version with this approach (thanks, XOR LX: see here) which might be very useful as INDEX can take arrays whereas OFFSET can only take references to a worksheet:
=SUMPRODUCT(A6:A8,INDEX(B6:B8,N(INDEX(1+ROWS(B6:B8)-ROW(INDIRECT("A1:A"& ROWS(B6:B8))),,)),0))
[As it happens with Excel's OFFSET version above, the formula with the N(INDEX([...],,)) modification does not work in OpenOffice, the wrapping function must be taken out if using that application.]
The approach is analogue to the one used in Excel for OFFSET. Take into account that INDEX uses indexes starting with 1 whereas OFFSET starts with 0. As it happens with the previous case, an array is dynamically created from the row numbers in A1:A3 to be used as both template for the array and position change index.
This very late answer is unlikely to help the original poster, but it might save time to future users with a similar question.
I cannot see a solution that doesn't involve (a) custom functions in VBA (or similar) or (b) an extra column with partial results.
If you don't like column C becoming a (hidden) reverse list, would you accept column C becoming a list like: A1*B3, A2*B2, A3*B1, which could then be summed? It would be possible to use a similar formula to the one mentioned in #e.tadeu's answer to obtain this (using OFFET and ROW functions.)

Resources