+ Reply to Thread
Results 1 to 36 of 36

Formula To Average Recent Groups

  1. #1
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Question Formula To Average Recent Groups

    Hey all, I'm having trouble figuring out how to make a formula that will give me the average values of a recent group, and am hoping that somebody here will have a suggestion.

    The formula needs to do this: Search the sheet for all the efficiency values of the five most recent dates by a specified user, calculate the average of these values, and display that number in a cell.

    See the attached example. The colours are only there for clarification - they specify which cells are grouped, for example, purple indicates the five most recent dates for WILL, so all six efficiency values for those dates need to be averaged and displayed in Cell C3, in this case 145.

    This will then need to be applied for the 2nd though 5th groups as well. Any thoughts?
    Attached Files Attached Files
    Last edited by swordswinger710; 06-28-2018 at 10:42 AM.
    There is so much good in the worst of us,
    And so much bad in the best of us,
    That it hardly behooves any of us
    To talk about the rest of us.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Formula To Average Recent Groups

    Are the coloured cells something you've done manually to help us towards the solution you're looking for or are you expecting the formula to pick up the colours?

    Formulas can't detect cell colours, that's only possible via VBA (unless the cells are coloured using Condtional Formatting).
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Formula To Average Recent Groups

    Try this:

    G3 =LOOKUP(2,1/((COUNTIF($F3:F3,$B$16:$B$61)=0)*($A$16:$A$61=$A$1)*(MID($J$16:$J$61,7,1)+0=$B3)),$B$16:$B$61)

    Drag through K3 then down through row 7.

    C3 =IFERROR(AVERAGEIFS(H:H,A:A,A$1,B:B,">="&K3,J:J,"GROUP "&B3&" *"),"MORE DATA RQD")

    Drag down through C7.

    See attachment. The helper cells (G3:K7) can be placed anywhere or even hidden.
    Attached Files Attached Files
    Last edited by 63falcondude; 06-28-2018 at 10:33 AM. Reason: typo

  4. #4
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    @Special-K The colours are only there to aid in clarification, I updated my original post to reflect this.

    @63falcondude Thank you, this gets me the results on my example, however, users need to be able to continue adding data, and as they do, the groups (and therefore the average efficiency results) will need to constantly update.

  5. #5
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Formula To Average Recent Groups

    Then extend the range of the formula in G3 to account for as much data as you will need. For example:

    =LOOKUP(2,1/((COUNTIF($F3:F3,$B$16:$B$1000)=0)*($A$16:$A$1000=$A$1)*(MID($J$16:$J$1000,7,1)+0=$B3)),$B$16:$B$1000)

    Everything is automated after initial setup.

  6. #6
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    Oh, I see, you're using the CLARIFICATION column as well. I just put that in there to help clarify the way the groups should work. Users won't be adding that data.

    Couldn't we use just one helper column that would automatically calculate the group number, and then have one formula set up to use that helper column data to calculate the average?

  7. #7
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    This setup works great for finding the average of all the entries for the five most recent days, and uses one helper column, hence why I think something similar should technically work for groups as well, but maybe it's not quite that simple?
    Attached Files Attached Files

  8. #8
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Formula To Average Recent Groups

    So the CLARIFICATION column will not be in your actual workbook? I assumed that the workbook from post #1 was a representative sample.

    This changes things...

    Couldn't we use just one helper column that would automatically calculate the group number
    We could automatically create the groups in ascending order (group 1 being the oldest) but it doesn't make sense to me to have group 1 as the newest date as you're showing in your sample.
    That would mean that the groups will constantly be changing (group 1 will become group 2 which will become group 3 etc.) as more data is added.

    ... and then have one formula set up to use that helper column data to calculate the average?
    The most efficient way that I know of calculating the 5th most recent unique date in this example is what I did in cells G3:K7.

    If there was a formula to populate the date in cell K3 without using the method that I used, I would have done that and replaced K3 with that formula in the C3 formula.

  9. #9
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    No, I just threw the CLARIFICATION column in to help explain how the groups work. I suppose it could be in there if the values in the column are added automatically though.

    And actually, yes, I think you described the groups perfectly. Group 1 is supposed to represent the five most recent days of efficiency values, Group 2 is the five 2nd most recent days of efficiency, and so on. Which means that once there are five newer entries for WILL, what would have been Group 1 five days ago is now Group 2.

    Would my most recent post (#7) be of any help?

  10. #10
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Formula To Average Recent Groups

    Would my most recent post (#7) be of any help?
    Not in this case.

    This has become more involved than I had originally intended. I'll let others know this is here so that they can give it a whirl if they'd like.

  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,809

    Re: Formula To Average Recent Groups

    Swordswinger - this idea is overly convoluted. I would suggest you rethink the way you are doing this and come up with a simpler layout. Having to constantly alter group names as data is added is ludicrous!
    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.

  12. #12
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    Hello again, AliGW, lovely to see you again.

    What I'm ultimately after is not so much the altering of group names, but instead, trying to create a formula to pull data from the most recent dates.

    Perhaps this is simpler way of putting it: If I could somehow figure out how to get the average result of data taken from five of the most recent entries, I feel like I would be half-way there.

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    Apologies for not getting back to you on this, things came up and your other thread on this (which you should have stuck with) got pushed down.

    I will take another look for you.

    Just to recap, you want the average - per name - of the (1st) last 5 dates, then the avg of the 6-10 last dates?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  14. #14
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    No worries FDibbins, I thought starting over more clearly would be helpful, but it doesn't seem that simple.

    And yes, your recap seems correct. The 1st last 5 dates are the closest 1-5, the 2nd last dates are the closest 6-10, the 3rd 11-15, etc.

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    OK I can come back to your 1st answer (145) with this ARRAY beast...
    =AVERAGEIFS($H$16:$H$61,$A$16:$A$61,"will",$B$16:$B$61,">"&LARGE(IF($A$16:$A$61="will",$B$16:$B$61),1)-6-ROWS($E$1:E1),$B$16:$B$61,"<="&LARGE(IF($A$16:$A$61="will",$B$16:$B$61),1))
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    But then if I drop the latest date (24 Nov), I get 159.8, or if I drop the earliest of 5 dates (20 Nov) I get 166.2, not 153

  16. #16
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    aahh OK, I just saw your latest post. Back to the drawing board, but I think I have the principal down now

  17. #17
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    hmmm your data is very "dirty" for a name (Will), you have in-sequence dates (1, 2, 3 etc), out-of-sequence dates (1, 3, 4, 6) duplicate dates (not a problem) and different names mixed together for the same date
    R
    S
    33
    WILL
    14-Nov-18
    34
    BOB
    14-Nov-18
    35
    WILL
    14-Nov-18
    36
    BOB
    14-Nov-18
    37
    WILL
    14-Nov-18

    These are throwing all sorts of curve balls

    1. Can you sort your date?
    2, Would you be OK with a helper (to ID unique name/dates), which could be hidden?

  18. #18
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    Yeah, users enter data this way all the time, but maybe we could sort the rows on another sheet? And hidden helper columns are no issue whatsoever.

  19. #19
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    IF you can sort your data, this regular formula gives the same values as you did in your sample....
    =AVERAGEIFS($H$16:$H$61,$A$16:$A$61,$D$1,$C$16:$C$61,">="&ROWS($A$1:A1)*5-4,$C$16:$C$61,"<="&ROWS($A$1:A1)*5)
    copied down

    Then in a helper column (I used C, you can use whatever you want, just change the BOLDED ranges...
    C16=IF(A16<>$D$1,0,IF(OR(B16<>B17,A16<>A17),MAX($C17:C$62)+1,MAX($C17:C$62)-1))
    copied down

  20. #20
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    If you want, the data can be sorted on the same sheet - just sort by Date, then Name

  21. #21
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    This is exciting! Which sample are you using for this? I've having trouble lining up the data.

  22. #22
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    I have attached the file I worked on, I added sheet1 then sorted the data
    Attached Files Attached Files

  23. #23
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    Alright, I will check this out, thank you so much!

  24. #24
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    Keep me posted

  25. #25
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula To Average Recent Groups

    swordswinger710 I do not understand this part ...
    The formula needs to do this: Search the sheet for all the efficiency values of the five most recent dates by a specified user, calculate the average of these values, and display that number in a cell.
    How do we determine 5 most recent dates when with one exception they are all in the future ... starting with 1-Oct-18.

    What am I missing?
    Dave

  26. #26
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    Quote Originally Posted by swordswinger710 View Post
    No worries FDibbins, I thought starting over more clearly would be helpful, but it doesn't seem that simple.

    And yes, your recap seems correct. The 1st last 5 dates are the closest 1-5, the 2nd last dates are the closest 6-10, the 3rd 11-15, etc.
    FT, from post 14, maybe this will make it clearer?

  27. #27
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula To Average Recent Groups

    Ah! Thank you Ford.

    I scanned through the posts looking for some kind of clue.

    I missed the point of that one.

  28. #28
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    Took me a while to catch on, too lol, that post did it for me though

    Just for S's and G's, see what you come up with, you're a pretty good formula-smith

  29. #29
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula To Average Recent Groups

    Well I am confused.

    I put a helper column in I16:I61 to get Group numbers.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then this duplicates expected results. It makes no sense to me because it includes none of the qualifiers mentioned so far.

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

  30. #30
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    FlameRetired, the CLARIFICATION column is just there to help explain how the groups work, which means they won't normally be there.

    Is there a way to make the helper column "I" figure out the most recent 5 groups for each user in the list, giving us the same results as it is now, but without using the CLARIFICATION column? That would solve this, I think.
    Last edited by swordswinger710; 06-29-2018 at 07:57 AM.

  31. #31
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    Sorry for the delay, was a bit tied up.

    Did my suggested file work at all for you?

  32. #32
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula To Average Recent Groups

    Is there a way to make the helper column "I" figure out the most recent 5 groups for each user in the list, giving us the same results as it is now, but without using the CLARIFICATION column? That would solve this, I think.
    Yes. I have a solution that currently uses array constants ... which assume 5 groups.

    Those can instead be made reliably dynamic if ... there are not multiple groups with < 5 unique dates. Though I haven't tried it yet I question whether my ranking strategy will work.

    If there are it will be back to the "salt mines".

    The attached has:

    A helper column C that returns unique dates for WILL.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    A rank column D that ... ranks those dates.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Then column E returns the group #s.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Then D3:D7
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by FlameRetired; 07-01-2018 at 02:03 PM.

  33. #33
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Formula To Average Recent Groups

    Thanks again everyone, great methods here which seem functional, despite being a bit bulkier than I originally thought they'd need to be.

    What do you think about the method attached? This is more in the simplified direction that I was originally thinking, and the only issue I'm finding with it is when the dates aren't entered in ascending order.

    Do you guys have any idea if that last issue can be resolved while maintaining this method?
    Attached Files Attached Files

  34. #34
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula To Average Recent Groups

    despite being a bit bulkier than I originally thought they'd need to be.
    Given the convoluted nature of the problem this doesn't seem a reasonable expectation.

    This is more in the simplified direction that I was originally thinking ...
    So why not use that?

    ... , and the only issue I'm finding with it is when the dates aren't entered in ascending order.
    What I believe you are saying is that the example given is not truly representative of the real problem.

    Having said that would you upload something reflecting the real problem? Please give us a "worst case" scenario.

    If not perhaps it's time for you to ask Mod/Admin move this project to Commercial Services.

  35. #35
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula To Average Recent Groups

    as for the sorting, you could set up (record) a quick macro that will do that all for you at the press of a button?

  36. #36
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula To Average Recent Groups

    Another try. Managed to shrink it a bit, and I am not sure how this will work for all the situations you envision. Try it and let me know.

    In D1:E1 two methods for calculating count of unique dates that are "WILL". D1 array entered.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    In E1 non array entered.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Reference either one for the helper column in I.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. Formula To Average N Most Recent Group
    By swordswinger710 in forum Excel General
    Replies: 15
    Last Post: 07-03-2018, 09:00 AM
  2. Formula To Average N Most Recent Group
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2018, 01:57 PM
  3. Groups no longer appear in Recent People
    By taylorsm in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 11-14-2017, 12:30 PM
  4. [SOLVED] Average most recent 3 values excluding dashes - array formula help required
    By cricket_stoner in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-04-2017, 08:00 AM
  5. Replies: 2
    Last Post: 01-04-2016, 03:40 AM
  6. Formula to average 3 most recent scores by date, then subtract baseline
    By kslattery in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-18-2014, 11:16 AM
  7. most recent average value
    By Joe Miller in forum Excel General
    Replies: 5
    Last Post: 12-23-2008, 08:43 AM

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