+ Reply to Thread
Results 1 to 20 of 20

Index Match with date range criteria

  1. #1
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Index Match with date range criteria

    Attached is an Excel 2010 workbook with multiple worksheets. It will open up to the one I need help with and the column header is highlighted in yellow to show which column has the formula I need help on. The amounts showing are accurate but the formula is having trouble on some of the lines.

    Here is an explanaiton of the worksheets included in the file:
    Doc List - this lists all the documents associated to the projects listed in the Project List worksheet. It shows whether the version of the document listed is the most current. It shows the type of work involved. It shows the total cost of the doc. There are formulas to show how much of that work is Captial and how much is Expense. (These formulas will be adjusted but are not used for the formula I need help on.) It also shows which document and the date of said document replaces the individual amounts on the current doc. What this means is: each doc will have a list of items and their individual costs. We might receive another document that shows just the increased amount of those same items. Therefore both documents are current docs with the sum of both docs equaling the new line item totals.

    Fixed - This worksheet shows those individual line items in the docs. It shows the total amount, tha capital ratio for each item which then calculates the total cap and total exp amount per line item. It shows the date that line was added to the file. There is a formula to show if that line item was replaced by another and the date it was replaced. This is very important. We may accrue part of that line prior to it being replaced by another doc and this will be shown on the next worksheet.

    Accruals-Pmts - This sheet is where each month the user will go in and list those line items that are being accrued. The date in Col K is important to show when this transaction was done. The amount in Col N is what I need help with. It should return the amount of the line item at the time the accrual is being done. To explain a little more, if col K shows the date as May-13, the date behind that is 5/1/13. The accruals are done at the end of the month so the formula in N needs to change the date in Col K to endofmonth. Then it needs to look up the amount that was in play as of endofmonth May 2013 on the Fixed worksheet without going over. So if the Fixed sheet shows this item listed twice, once with 5/1/13 in Col U on the fixed sheet and once with 7/7/13, the formula in the Accruals-Pmts sheet should pull the corresponding data associated to the 5/1 date and not the 7/7/13 date.

    I really hope this makes sense. If not, please ask specific questions and I will try to be more clear. Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Index Match with date range criteria

    Nice formula
    But there is a syntax error in it:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The 1 doesn't belong there.

    Syntax is MATCH(SearchValue, SearchMatrix, [CriterionType])

    Unfortunately I can't correct it for you as I have not clue of what it's supposed to do.
    Last edited by Tsjallie; 10-12-2013 at 03:14 PM.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Index Match with date range criteria

    Is this what you want?
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    When an Index Match formula is matching to more than one value, I've always seen the formula written with the 1 in it. As for what this is supposed to do, it needs to return the amount of the item in Col M as of the date in Col K based on what's in the "Fixed" worksheet. If you have ideas to make this work, I welcome them. Thanks so much.

  5. #5
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    Thanks for your help. Unfortunately, the formula you gave is not finding the subsequent values of the item in Col M. You can see that for rows 4&5 there is no dollar amount and there should be. The formula seems to only be finding the first instance.

    Is the Month part of the formula going to find the right value if there was a change twice in one month? Is it taking into account year as well?

    For some reason when I put your formula into my main file (not the stipped down one I sent here), the formula comes up with the #VALUE! error. I'm still trying to figure that one out.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Index Match with date range criteria

    There is no values in row 4 & 5 because there is no corresponding data for following matching record in Fixed sheet.
    row-5--> P512-1 - TB Fixed - Jul-13
    row-4--> P512-1 - TB Fixed - Jun-13

    The above two records, I don't see on Fixed sheet.

    Did you notice that? Or I am missing something?

  7. #7
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    The formula needs to find the amount if the end of the month on row 4 and 5 is greater than or equal to the date on the Fixed sheet.
    So row 4 has a date of Jun-2013 (which translates to 06/01/2013). The date on the Fixed sheet is 05/15/2013. Therefore as long as the end of the month on the accrual sheet is not greater than the date on the Fixed sheet, the formula should return the amount associated to the 05/15/2013 date. I hope this makes sense. Thanks so much for all your help.

  8. #8
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Index Match with date range criteria

    Still not sure if I really understand the idea, but may be I'm getting a clue.
    If I'm right this should work:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    (Applies to row 3)

  9. #9
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    Tsjallie, The formula works perfectly until you drag it to row 9. Here I need it just to find $197,854.43 instead of summing up that number times however many times the match appears. Unfortunately the Sumif formula sums the number in column S however many times it finds the match. Instead I need it to only return the number once.

    Let me see if I can explain a bit more. The Fixed sheet lists all of the items (col L) per doc short name (col J). You can see that the full doc name (col I) may vary but the short doc name (col J) combines the similar docs into one consistent name without losing the original name of the original docs. The work performed , accrued, and invoiced will be against whichever revision of the doc that applies so we can't easily say one entire doc replaces another. You can see that doc short name P308-128 had item "EofC" originally listed at a cost of $156,924.42 when it first appeared on the docs. The next doc again listed this item ut now it had a cost of $97,854.43. The third version of the doc had the item and price the same. Now when we first got the doc we accrued a portion of this item at its original cost. The next accrual was still at the original cost as the first revision was not received. The third accrual is now against the revised doc. Therefore the Accrual worksheet Col N needs to show the price of the item at the time it was accrued. I hope that helps clarify what I am trying to accomplish. Thanks so much for your time.

  10. #10
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    In reading my last post, it appears some of the letters I typed did not appear. Here is a clean version of that text:

    Let me see if I can explain a bit more. The Fixed sheet lists all of the items (col L) per doc short name (col J). You can see that the full doc name (col I) may vary but the short doc name (col J) combines the similar docs into one consistent name without losing the original name of the original docs. The work performed, accrued, and invoiced will be against whichever revision of the doc that applies so we can't easily say one entire doc replaces another. You can see that doc short name P308-128 had item "EofC" originally listed at a cost of $156,924.42 when it first appeared on the docs. The next doc again listed this item but now it had a cost of $197,854.43. The third version of the doc had the item and price the same. Now, when we first got the doc we accrued a portion of this item at its original cost. The next accrual was still at the original cost as the first revision doc was not received. The third accrual is now against the revised doc. Therefore the Accrual worksheet Col N needs to show the price of the item at the time it was accrued. I hope that helps clarify what I am trying to accomplish. Thanks so much for your time.

  11. #11
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Index Match with date range criteria

    Sorry, I overlooked Fixed!S:S being cumulative already. So summing doesn't make sense.
    So you need to find the last row in the Fixed table satisfying all the criteria. The match function gives you the first instance.
    Trouble is that the array you're finding with the match formula contains multiple equal values (0's and 1's). That means that you need to find a way to generate an array with all unique numbers. That can be done be multiplying the 0's and 1's with the row number. Then it's ok when match finds the first instance. Next thing to solve is how to determine the value to search for. That must be done be finding the max value in the array generated. Meaning that the formula genrating the array must be executed twice: one time to determine the value to search for and the second time to generate the array to search in.
    That gives the following formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I used column A for the row number, but that can be any row.
    I'm also posting the workingbook with the formula in it.
    Do notice that I limited the ranges. This makes calculation much faster. Also consider giving these range a name. That would improve the readability of the formula.
    Attached Files Attached Files

  12. #12
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Index Match with date range criteria

    Excellent use of index and match functions.

    I hope this will give NS4Excel the desired results.

  13. #13
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Index Match with date range criteria

    Thx for the appreciation, sktneer.
    But it's also a candidate for the ugly formula competition.

  14. #14
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Index Match with date range criteria

    lol......but no doubt the problem was interesting indeed.

  15. #15
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    Thank you for the formula. I'm including a new file to show what's actually happening in my file. I don't know if why the formula isn't entirely working is due to other formulas I have in my file or if it's due to something else.
    Attached Files Attached Files

  16. #16
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Index Match with date range criteria

    OK. Looks messy, but it's not that worse. Here's what going on with the formula.
    In case of the formula in (e.g.) cell N6 no matches are found in the Fixed sheet, thus giving an array of all zeroes.
    This makes the max value 0 and so the value to look for is 0. The match function then looks for 0 which is the first value in the array.
    And so the index function returns the first row from Fixed!S2:S44 which is "Total".
    All the other errors you see in the sheet come from this error, because they - directly or indirectly - use the result of the formula.

    Now there are several ways to solve this:
    1. A very simple one which just masks the problem, but doesn't really solve it. It means putting a zero in cell Fixed!S2 and giving it a custom format of type "Total"
    2. A complex one which means extending the formula (again) to check if there are any rows found and the return 0 if not.
    3. An elegant one which also extends the formula, but uses names for the subformulas. This makes the formula readable and very easy to adjust, because they are stored on one place.
    4. A more difficult one, but giving a lot of extra possibilities. This would be a user defined function. This would need you to gather some basic vba knowledge.

    The workbook I'm posting for now uses the first option. But I would strongly advise you to go for the 3 one.
    I will post a sample of that tomorrow.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    Thanks Tsjallie. I look forward to seeing the formula to your 3rd idea as I'm not a fan of masking issues. Also I have other formulas that caluclate based on the results of this one and don't want to risk those ones having issues. I really truly appreciate all your help on this. I could not do this without you!

  18. #18
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Index Match with date range criteria

    Here's the workbook with the named formulas.

    The formula in (e.g.) cell N6 now looks like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The part marked red solves the problem with not finding any matches and thus retrieving unwanted data.

    Introduced the following names:
    TypeIsFixed which holds
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ValueToLookFor which holds
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ArrayToSearch which holds
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Notice that ValueToLookFor in it's turn uses ArrayToSearch.
    This means that - with the same technique - you could also further break up ArrayToSearch which still holds a long formula.

    Also you can use this technique for the ranges you are referencing.

    This way of working gives you some major benefits:
    1. It improves the readability of your formulas, thus preventing errors or makes debugging them more easy
    2. If you need to alter a formula you only need to do that in the definition of the name (see Formulas - Manage names on the ribbon). Same goes for named ranges. This can save you an awfull lot of work.

    One warning though:
    the formulas use (partly) relative references. Just like with directly entered formulas their behaviour and result differs depending on the cell they are used in.
    So do keep track of where you are in your sheet.
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    10-11-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Index Match with date range criteria

    Tsjallie, this works perfectly. Thank you so much for your assistance on this!

  20. #20
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Thumbs up Re: Index Match with date range criteria

    Glad to hear that!
    And thanks for letting me know

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Index match, within a certain date range
    By Spreadsheetdaunting in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-08-2013, 01:02 AM
  2. [SOLVED] Using Index/Match using criteria including range between two cells
    By fer907 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-10-2013, 04:07 PM
  3. Index / match 2 criteria row and column containing date - please help!!
    By willgt in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-22-2013, 08:03 PM
  4. [SOLVED] Index match formula to search for two criteria (date & name)
    By davechamp1983 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-17-2012, 10:00 PM
  5. Replies: 3
    Last Post: 08-17-2010, 02:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1