+ Reply to Thread
Results 1 to 28 of 28

How To Calculate Running/Ongoing Value When More Data Is Added?

  1. #1
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    How To Calculate Running/Ongoing Value When More Data Is Added?

    Hi

    I have attached a simple example for the question I have.

    Basically there is a list of 90 football matches with results. I have split the series of games into 9 match days (column A) and I want to calculate the goal difference of each team going back the previous 2 match days.

    For example:

    Rows 2 to 21 contains just results but H22, I22 begins to show the goal difference (GD) for each side based on how the teams performed in their previous 2 games. You will see that Bologna won 3-2 (row 5) and lost 1-0 (row 15) in their 2 games, this gives a GD of 0 (won by 1 goal and lost by 1 goal, +1 minus -1)

    Entering this manually is easy enough but how would I enter a formula (or VBA) that calculates this value for potentially thousands of rows?

    You will see the 2 rows (22 and 23) which shows what the result should be. Bologna's next game (match day 4) should only consider the goal difference from match days 2 and 3, ignoring match day 1 and so on.

    Any help will be appreciated!

    Thank you
    Attached Files Attached Files
    Last edited by philwaters; 07-07-2019 at 05:02 PM.

  2. #2
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,823

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Assuming every team plays each match day, you can try these formulas:
    In cell H22:
    =SUMIFS(E:E,A:A,">"&A22-3,A:A,"<"&A22,C:C,C22)-SUMIFS(F:F,A:A,">"&A22-3,A:A,"<"&A22,C:C,C22)-SUMIFS(E:E,A:A,">"&A22-3,A:A,"<"&A22,D:D,C22)+SUMIFS(F:F,A:A,">"&A22-3,A:A,"<"&A22,D:D,C22)

    Then you can copy it down. In cell I22, you can enter this formula:
    =SUMIFS(E:E,A:A,">"&A22-3,A:A,"<"&A22,C:C,D22)-SUMIFS(F:F,A:A,">"&A22-3,A:A,"<"&A22,C:C,D22)-SUMIFS(E:E,A:A,">"&A22-3,A:A,"<"&A22,D:D,D22)+SUMIFS(F:F,A:A,">"&A22-3,A:A,"<"&A22,D:D,D22)
    And again, copy it down.

    I'm quite sure this is NOT the most efficient way to do this, so stay tuned for some nicer formulas, but since no one else has answered yet, and these work, i thought I'd post them.

  3. #3
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49
    Thanks for the reply Greg.

    I will give it a go later when I have time after work. The only issue is I am certain some teams will miss a match day due to various reasons. They will all play the same amount of games in the season but postponements and rearranged games can play a part in not all 10 matches being played in the same week.

  4. #4
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Well it works, Greg.

    Thank you for taking the time to work this out for me.

    What is the concern with teams that miss a match day?

  5. #5
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,823

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Well, the formula goes back 2 "Match Day's". So if you are on Match Day #6, and the team didn't play Match Day#5, then it will only get the difference for Match Day #4. It doesn't go back to the last 2 matches the team played, it goes back 2 "Match Days". Not sure if that's an issue or not.

  6. #6
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Ah I see. Yes that is a problem.

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,445

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Rather then using formulas containing entire columns ( which is bad practice), you can use Excel's "Table" tool.
    Each time you add a row, the formula adapts.
    Explanations can be found, for example at https://www.contextures.com/xlExcelTable01.html

  8. #8
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Yes a table is definitely the way to go here.

    I was wondering - is it not possible to use the team name rather than the match day column (A) to find the teams and do the calculations?

    So instead of calculating back 2 match days, we calculate back 2 team name occurrences? The issue is that the team name alternates from one column to the other depending on whether they are playing at home or away. But I feel this would solve the problem of missing a match day.

    Any thoughts, anyone?

  9. #9
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    I think the answer lies in searching for the last 2 occurrences of a team name in either column and working out the sum of goals scored and conceded from those results.

    So how do I search for the last 2 occurrences of the team?

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    This will find the last occurrence:

    =LOOKUP(2,1/(A:A="Team"),A:A)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    So, to get you started, in H2 copied down:

    =IFERROR((E2-F2)-(LOOKUP(2,1/(C$1:C1=C2),E$1:E1)-LOOKUP(2,1/(C$1:C1=C2),F$1:F1)),"-")

    and possibly in I2 copied down:

    =IFERROR((F2-E2)-(LOOKUP(2,1/(D$1:D1=D2),F$1:F1)-LOOKUP(2,1/(D$1:D1=D2),E$1:E1)),"-")
    Attached Files Attached Files
    Last edited by AliGW; 07-10-2019 at 03:23 AM.

  12. #12
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Thanks for doing this work.

    My first impression is that something is not right though. Bologna's goal difference in match day 3 should be 0 based on the previous 2 games where they won by 1 goal and lost by 1 goal. Their opponents, Fiorentina, should be on a GD of +1 (or simply 1).

  13. #13
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Columns H and I represent the goal differences going into the match in question based on the information from the last 2 matches played.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Yes, there is something wrong. I had not realised that you need to look at both columns. It will give you a start, though - the principle of finding the last two games is essentially the same.

  15. #15
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Having looked at the formula, it is on the right path but not quite there.

    What it needs to do is look at Bologna and see they won 3-2 two games ago and count that as a GD of 1, then find the next occurrence of Bologna and see that they lost 1-0 (when away) and count that as a GD of -1, then add both of those together and display the answer in H22 (answer should be 0)

    I am only using 2 previous games to get the formula ready, the amount of games to consider will be much larger but thought it best to get the calculations right first.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    I assume the last two matches for any team wiill be one home and one away fixture?

    See if this works for home GD:

    =IFERROR((LOOKUP(2,1/(C$1:C21=C22),E$1:E21)-LOOKUP(2,1/(C$1:C21=C22),F$1:F21))+(LOOKUP(2,1/(D$1:D21=C22),F$1:F21)-LOOKUP(2,1/(D$1:D21=C22),E$1:E21)),"-")

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    And this for away:

    =IFERROR((LOOKUP(2,1/(C$1:C1=D2),E$1:E1)-LOOKUP(2,1/(C$1:C1=D2),F$1:F1))+(LOOKUP(2,1/(D$1:D1=D2),F$1:F1)-LOOKUP(2,1/(D$1:D1=D2),E$1:E1)),"-")

  18. #18
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    The home one looks correct - as far as producing the correct result (tried it down a few teams) - but the away one is not playing well for some reason.

    Just to answer your other point above, teams will not necessarily alternate from home and away, they could play consecutive games home or away and not sequentially. I want to capture any occurrence of a team playing.

    Thanks so far - great work.

  19. #19
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Amended the away formula to:

    =IFERROR((LOOKUP(2,1/(C$1:C21=D22),E$1:E21)-LOOKUP(2,1/(C$1:C21=D22),F$1:F21))+(LOOKUP(2,1/(D$1:D21=D22),F$1:F21)-LOOKUP(2,1/(D$1:D21=D22),E$1:E21)),"-")

    Seems to be working now. On my way from work, so I will give it a full bash soon and report back.

  20. #20
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    OK, well you'll need to work on it a bit more, then. Hopefully I've pointed you in the right direction. Let us know how you get on and if you need any further pointers.

  21. #21
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Still haven't fully tested yet but I will do when I'm home. My other concern though is the lookups are going to spot the first occurrence and no more so when I increase the number of matches which include multiple home and away and not sequential, I am going to hit a brick wall.

    I think some sort of combination of Greg's effort (sumifs based on match day column) and yours Ali is the solution just waiting to be discovered!

  22. #22
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,823

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    The attached file works, as best as I can tell. Again, it is not the elegant solution, but it works. I haven't looked at the formula above to see if I can make it easier yet.

    First, I put it in a table. Then I added two columns which count the number of times a team shows up up until that game.

    Now it doesn't matter if they play every Match day or not. They can skip and it still works.

    When I get a chance to look at the above formula, I will see if I can create a formula without having to add the two columns (although the 2 additional columns don't hurt anything and you could even hide those columns as they are automatically populated because of being in the table.
    Attached Files Attached Files

  23. #23
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,823

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    By the way, my solution does not care if the teams are playing home or away in any sequence (they can play 2 home games, then 3 away games and it should still work). (An example to test is for the GD for Carpi's 4 Match Day. Carpi plays as the Away team for both match day's 2 and 3, giving a GD of -2 for Match day 4.)

  24. #24
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Just had a quick glance there Greg and it seems to be working. I will test it later for real but looks like excellent work.

    The bigger challenge will be increasing the number of matches and allowing the goal difference to be calculated over 32 matches. But I figure this will be an easy adjustment based on your formula above.

    Superb work Greg.

  25. #25
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  26. #26
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,823

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    I've attached a version where at the top of the table, I have a place where you can enter any number you want as far as how many matches you'd like to go back.

    So just change that number and all the calculations change appropriately.
    Attached Files Attached Files

  27. #27
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Utterly superb work there Greg. I am going to give it a true test at the weekend. The overall aim is to use a rolling 32 matches to gather the required GD figure. This will present a further problem down the line when teams who were promoted from a division below or relegated from a division above (where applicable) have their GD calculated using games from a different division.

    One step at a time though and from an idea that has been swimming around in my head for a long time, giant leaps have been taken with this forum's help.

  28. #28
    Registered User
    Join Date
    08-18-2013
    Location
    Wembley
    MS-Off Ver
    Office 365
    Posts
    49

    Re: How To Calculate Running/Ongoing Value When More Data Is Added?

    Just out of interest, when you change the figure at the top to change the number of matches - looking at the results, I presume it still works out the figures for every number of matches below that figure? Otherwise, if I set the figure to 10, I was half expecting the GD figures to be 0 until 10 matches were reached.

+ 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. Running average from a large range of ongoing cells
    By onin2golf in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-05-2013, 12:56 PM
  2. Replies: 4
    Last Post: 03-16-2013, 05:52 PM
  3. Calculate a running average off a conditional sum
    By TGCRequiem in forum Excel General
    Replies: 12
    Last Post: 04-10-2010, 03:22 PM
  4. Calculate a running grand average from multiple worksheets
    By rangercole in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2009, 10:05 AM
  5. [SOLVED] Adding an ongoing value to an Average
    By biggcheese in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  6. [SOLVED] Adding an ongoing value to an Average
    By biggcheese in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  7. [SOLVED] Adding an ongoing value to an Average
    By Peo Sjoblom in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  8. [SOLVED] Adding an ongoing value to an Average
    By biggcheese in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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