+ Reply to Thread
Results 1 to 5 of 5

Displaying the last value corresponding to the last occurrence of a combination

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    Stgo, Chile
    MS-Off Ver
    Excel 2010
    Posts
    46

    Displaying the last value corresponding to the last occurrence of a combination

    Hi all!!

    So I have two Columns (B and C) which combined make 1 name and have a value associated to them (which changes every time the combination occurs).

    I need to check what was the previous value for the combination so I can see whether the newer occurrence was higher or lower.

    I think I got part of the problem, as you can see in the attachment, but I need it to display just the previous one, and not keep on adding.

    ExampleOccurances.xlsx

    By the way, the table is much bigger than this and will continually grow.

    Thanks so much.
    Last edited by kiwinho; 08-28-2012 at 01:05 PM. Reason: Solved

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Displaying the last value corresponding to the last occurrence of a combination

    Using your posted workbook...
    This regular formula returns the previous Value for the Name/Line combination
    Please Login or Register  to view this content.
    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    Stgo, Chile
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Displaying the last value corresponding to the last occurrence of a combination

    Thank you so very much. Its perfect... Cheers!!

    ---------- Post added at 04:53 PM ---------- Previous post was at 04:52 PM ----------

    Do you think you could walk me through it? What part of the function does what, so I can try and use and tweak it some other time?

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Displaying the last value corresponding to the last occurrence of a combination

    Quote Originally Posted by kiwinho View Post
    Do you think you could walk me through it? What part of the function does what, so I can try and use and tweak it some other time?
    I'll do my best...

    This formula:
    =IF([@Recurrence]=1,"NA",IF(COUNTIFS($B$1:B2,[@Name],$C$1:C2,[@Line])>1,INDEX($E:$E,MAX(INDEX(($B$1:B1&"_"&$C$1:C1=[@Name]&"_"&[@Line])*ROW($B$1:B1),0))),0))
    discribes this way:
    • If this is the first recurrence:
    IF([@Recurrence]=1,"NA",
    .......return: NA
    Otherwise...
    • If the Name/Line combination exists above the current row:
    IF(COUNTIFS($B$1:B2,[@Name],$C$1:C2,[@Line])>1,
    ...return the Value from the last previous instance:
    INDEX($E:$E,MAX(INDEX(($B$1:B1&"_"&$C$1:C1=[@Name]&"_"&[@Line])*ROW($B$1:B1),0)))
    ...Otherwise...return zero:
    ,0)


    This is the interesting part:
    MAX(INDEX(($B$1:B1&"_"&$C$1:C1=[@Name]&"_"&[@Line])*ROW($B$1:B1),0))

    This section:
    ($B$1:B1&"_"&$C$1:C1=[@Name]&"_"&[@Line])*ROW($B$1:B1)
    returns an array of Row_Numbers and 0's.
    If the row's Name/Line combo matches the combo on the line containing the formula
    ...the row_number is multiplied by 1
    Otherwise by zero.

    Technically, this part: ($B$1:B1&"_"&$C$1:C1=[@Name]&"_"&[@Line])
    returns a series of TRUE or FALSE values.
    However, when used in an arithmetic formula,
    TRUE becomes 1 and FALSE becomes 0.

    So, out of that series of 0's and row_numbers...the largest (MAX) row_number represents the last previous instance of the Name/Line combination.

    Now that we have the row number, we use it in the outer INDEX to find that row in column E.

    Of particular interest is the INDEX function inside the MAX function.
    Without it, you'd need complete the formula by holding down CTRL and SHIFT when you press ENTER
    ...instead of just pressing ENTER (to create an ARRAY FORMULA).
    Since nobody I work with EVER remembers to C+S+E, the INDEX function evaluates the returned values as an array without C+S+E.

    I hope that helps.

  5. #5
    Registered User
    Join Date
    08-23-2012
    Location
    Stgo, Chile
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Displaying the last value corresponding to the last occurrence of a combination

    This is brilliant! Very well explained, I really appreciate it. Best wishes.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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