+ Reply to Thread
Results 1 to 11 of 11

Thread: lookup formula

  1. #1
    Registered User
    Join Date
    03-18-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    6

    lookup formula

    I have a spreadsheet of soccer results. I would like to create a lookup formula of some kind that sums the goals scored by a team in the last five matches. So it should somehow be based on the date, as it should only include the five most recent matches, not matches played before that.

    Any suggestions?

  2. #2
    Forum Guru 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Vienna, VA, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2,242

    Re: lookup formula

    You don't really need a lookup, because you are not searching for a value. You can probably do this with some combination of SUMIF, COUNT, INDEX. But we need to know a little more about how your data is organized. Does your workbook deal with multiple teams? What data, and what columns is it in?

    I am not sure your title matches your question; you might consider changing it to something like "Sum five most recent events".
    Making the world a better place one fret at a time
    ||||||

    If someone helped you, please click on the star icon at the bottom of their post

    If your problem is solved, please update the first post:
    EDIT, Go Advanced button, set Prefix to SOLVED

    [code]
    ' Enclose code in tags like this
    [/code]

    Don't attach a screenshot
    --just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  3. #3
    Forum Guru zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    5,740

    Re: lookup formula

    Basically something like: =SUMIFS(C1:C20;A1:A20;">=10.3.2010";B1:B20;"a")

    But this has several problems: you need to enter 5th dat manualy (of course, you can use some aditional cells like D1 for date and D2 for club)

    =SUMIFS(C1:C20;A1:A20;">="&D1;B1:B20;D2)

    But best way would be that you upload some example workbook with some example data
    "Relax. What is mind? No matter. What is matter? Never mind!"

  4. #4
    Registered User
    Join Date
    03-18-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    6

    Sum five most recent events

    Thx for the replys. I am not at my home comp at the moment. I will upload an example workbook sometime tonight.

  5. #5
    Registered User
    Join Date
    03-18-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: lookup formula

    Here is my workbook, cleansed of unnecesary data.

    For any given match, I would like to sum up each teams scored goals in the five most recent matches.
    Attached Files Attached Files

  6. #6
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: lookup formula

    see this virtually identical thread from a few days ago: http://www.excelforum.com/excel-prog...lculation.html

    (there is an attachment in one of the last posts showing a formulae based approach)

  7. #7
    Registered User
    Join Date
    03-18-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: lookup formula

    Thank you, that was just what I was looking for and for the same purpose.

    For some reason, I cant get it to work on my spreadsheet though. I have uploaded my try, please check what I am doing wrong. It seems to me that the columns L and M are messed up, I just cant figure out why.
    Attached Files Attached Files

  8. #8
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: lookup formula

    The other thread was based on results in the reverse order to yours - ie most recent listed first.

    For the opposite - using your file:

    Code:
    G2: =IF(ISNUMBER($L2);SUMIF($B3:INDEX($C:$C;$L2);$B2;$D3:INDEX($E:$E,$L2));"")
    copied down
    
    H2:
    =IF(ISERROR($L2);"";SUMPRODUCT(($B3:$B$500=$B2)+($C3:$C$500=$B2);($D3:$D$500*($B3:$B$500<>$B2))+($E3:$E$500*($C3:$C$500<>$B2));--(ROW($B3:$B$500)<=$L2)))
    copied down
    
    I2:
    =IF(ISNUMBER($L2);SUMIF($B3:INDEX($C:$C;$M2);$C2;$D3:INDEX($E:$E;$M2));"")
    copied down
    
    J2:
    =IF(ISERROR($M2);"";SUMPRODUCT(($B3:$B$500=$C2)+($C3:$C$500=$C2);($D3:$D$500*($B3:$B$500<>$C2))+($E3:$E$500*($C3:$C$500<>$C2));--(ROW($B3:$B$500)<=$M2)))
    copied down
    
    L2:
    =SMALL(IF(ISNUMBER(SEARCH("@"&$B2&"@";$N3:$N$500));ROW($B3:$B$500));MIN(6;COUNTIF($B3:$C$500;$B2)))
    confirmed with CTRL + SHIFT + ENTER
    copied down
    
    M2:
    =SMALL(IF(ISNUMBER(SEARCH("@"&$C2&"@";$N3:$N$500));ROW($B3:$B$500));MIN(6;COUNTIF($B3:$C$500;C2)))
    confirmed with CTRL + SHIFT + ENTER
    copied down
    Note L & M are both Arrays... as per instructions you must ensure you commit using CTRL + SHIFT + ENTER as opposed to Enter as per "normal" formulae.

  9. #9
    Registered User
    Join Date
    03-18-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: lookup formula

    Thanks I got it working now. The last result of the other post was in the same order as mine though.

    One last thing I only want it to show a result if the team has actually played 6 matches and otherwise it should show False or something similar. Or should I post this in a new thread?

  10. #10
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: lookup formula

    I would suggest you modify the formulae in L & M such that less than 6 results generates an error .... so replace:

    MIN(6;COUNTIF($B3:$C$500;$B2))

    with

    6

    in both L & M formulae - remember to reset the Arrays with CTRL + SHIFT + ENTER once modified.


    Note that there is an error in the previously suggested formula will need to be corrected, I2 should read:

    ISNUMBER($M2)

    and not L2 as is presently the case.

  11. #11
    Registered User
    Join Date
    03-18-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    6

    Solved - lookup formula

    It works great, thanks a lot!!! i consider the subject solved.

Thread Information

Users Browsing this Thread

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

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.2.0