+ Reply to Thread
Results 1 to 14 of 14

Last N entries thet meet criteria

  1. #1
    Registered User
    Join Date
    04-26-2011
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    6

    Last N entries thet meet criteria

    Hello,
    I have a worksheet with football results from the English premier league. The columns contain data on the home team, away team, goals scored by the home team and goals scored by the away team. I need a formula that sums the goals scored by a team in the last 5 matches (both home and away). For example, if Arsenal have played 10 games, I would like to know the total number of goals scored by Arsenal in matches 6,7,8,9 and 10, and not from game 1,2,3,4 or 5.
    Thank You.
    Attached Files Attached Files
    Last edited by gunnar_; 04-26-2011 at 12:32 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Last N entries thet meet criteria

    Assuming you enter Arsenal in H1, then to get Sum of last 5 Home games...

    Please Login or Register  to view this content.

    confirmed with CTRL+SHIFT+ENTER
    not just ENTER.

    copy to next column cell to get last 5 away sum.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Last N entries thet meet criteria

    I came up with a non-array solution (I think) but requires two "dummy columns"
    In G2 dragged down
    =COUNTIF($C$2:$D2,C2)
    In H2 dragged down
    =COUNTIF($C$2:$D2,D2) You can hide these two columns if you like.

    Then with a unique list of teams in J2:J21, In K2;
    =SUMPRODUCT(--($C$2:$D$381=J2),--($G$2:$H$381>(COUNTIF($C$2:$D$381,J2)-5)), $E$2:$F$381)
    See attachment
    Attached Files Attached Files
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    04-26-2011
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Last N entries thet meet criteria

    Thank you for your quick response. The formula by NBVC seems to be working fine, but I needed the goals scored by a team in the last five games. It doesn't matter if the team had 3 home and 2 away games, or 1 home and 4 away. Is it possible to write such a formula?

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Last N entries thet meet criteria

    Try:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER

    This gives me 11, if I have Arsenal in I1

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Last N entries thet meet criteria

    Updated my spreadsheet with some test columns (I:K) and NBVC's formula. More times than not, the two are not agreeing. :/
    Attached Files Attached Files

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Last N entries thet meet criteria

    It was a matter or interpretation.

    My formula was calculated (probably wrongly) based on the team being the HOME team only (i.e I used column C only). Would need to adjust range for AWAY only.

    My last formula accounts for columns C and D together and picking the last 5 games played by the choice team (Home or Away)

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Last N entries thet meet criteria

    Even with the NBVC's new formula, the results don't match. Stoke for example only had 2 goals in the last 5 games by my calculations.

  9. #9
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Last N entries thet meet criteria

    You are correct, I apologize... I will need to rethink the formula....

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Last N entries thet meet criteria

    Okay, how about?

    Please Login or Register  to view this content.
    CSE confirmed.

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Last N entries thet meet criteria

    in g2 dragged down to g1000
    =IF(C2=$G$1,E2,IF(D2=$G$1,F2,""))
    put team name in g1
    in h1000 dragged UP to h2
    =IF(G1000="","",IF(COUNTIF($G$1000:G1000,">="&0)<=5,G1000,""))
    in h1 sum(h2:h1000)
    there are only 760 premiere league games so from 1000 covers it easily
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  12. #12
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Last N entries thet meet criteria

    Okay, now the three of us (NBVC, Martin and I) are in agreement. The world is a beautiful place.

  13. #13
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Last N entries thet meet criteria

    down to one helper now
    g1 team name
    h1 sum(h2:h1000)
    h2 down
    =IF(E2="","",IF(COUNTIF($C2:D$1000,$G$1)<=5,IF(C2=$G$1,E2,IF(D2=$G$1,F2,"")),""))
    Its all good practice!

  14. #14
    Registered User
    Join Date
    04-26-2011
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Last N entries thet meet criteria

    Thank you very much. You've helped me a lot. Good luck.

+ Reply to Thread

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.6.0 RC 1