+ Reply to Thread
Results 1 to 12 of 12

averaging every nth column working for all but 1 case

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-13-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    217

    averaging every nth column working for all but 1 case

    I attached a file. I have a long column in D which I want to average every 21 values.

    You can see the formula in column I.
    In I2, I average every 21st value in D starting in D2
    In I3, I average every 21st value in D starting in D3

    Why is my last one giving me the #DIV/0! error? It should correspond to every 21st value starting in D21
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,244

    Re: averaging every nth column working for all but 1 case

    Hi bj,

    I think it is because you don't have a proper If statement. You don't tell what to return if true and what if false. Try this instead.. Using CSE when entered

    =AVERAGE(IF(MOD(ROW(D2:$D$1953),21)=ROW($D2),D2:$D$1953),D2:$D$1953,0)
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    02-13-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: averaging every nth column working for all but 1 case

    Quote Originally Posted by MarvinP View Post
    Hi bj,

    I think it is because you don't have a proper If statement. You don't tell what to return if true and what if false. Try this instead.. Using CSE when entered

    =AVERAGE(IF(MOD(ROW(D2:$D$1953),21)=ROW($D2),D2:$D$1953),D2:$D$1953,0)
    This still confuses me. How can I create a formula like this for each case?

  4. #4
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: averaging every nth column working for all but 1 case

    Try

    =AVERAGE(OFFSET(D1,1,,21))
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  5. #5
    Forum Contributor
    Join Date
    02-13-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: averaging every nth column working for all but 1 case

    Quote Originally Posted by shukla.ankur281190 View Post
    Try

    =AVERAGE(OFFSET(D1,1,,21))
    I do not believe this works. The values are not correct.

  6. #6
    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
    53,048

    Re: averaging every nth column working for all but 1 case

    Because you included your file here, I will close your other thread, so you can continue here.

    The reason for your error if easy to see if you put the MOD and ROW() formulas in their own cells...
    E
    F
    2
    2
    2
    3
    3
    3
    4
    4
    4
    5
    5
    5
    6
    6
    6
    7
    7
    7
    8
    8
    8
    9
    9
    9
    10
    10
    10
    11
    11
    11
    12
    12
    12
    13
    13
    13
    14
    14
    14
    15
    15
    15
    16
    16
    16
    17
    17
    17
    18
    18
    18
    19
    19
    19
    20
    20
    20
    21
    0
    21
    22
    1
    22

    E2=MOD(ROW(D2:$D$1953),21)
    F2=ROW($D2)
    both copied down.

    As you can see MOD never gets higher than 20, but ROW just keeps incrementing.

    Did you see my suggestion in your other thread...
    J2=AVERAGE(D2,D21)
    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

  7. #7
    Forum Contributor
    Join Date
    02-13-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: averaging every nth column working for all but 1 case

    How could averaging 2 numbers possibly work? I have a very long column of numbers, and it seems like that would just average 2 numbers. If you look in column A, I have 20 values for each set, corresponding from 1 to 20.

    I want to average the values in column D that correspond to each A column value of 1. Then I want to do it for 2 etc.

  8. #8
    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
    53,048

    Re: averaging every nth column working for all but 1 case

    Quote Originally Posted by bjcowen9000 View Post
    How could averaging 2 numbers possibly work? I have a very long column of numbers, and it seems like that would just average 2 numbers. If you look in column A, I have 20 values for each set, corresponding from 1 to 20.

    I want to average the values in column D that correspond to each A column value of 1. Then I want to do it for 2 etc.
    Apologies, TOTALLY misread that 1

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,387

    Re: averaging every nth column working for all but 1 case

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.mrexcel.com/forum/excel-q...er-column.html
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: averaging every nth column working for all but 1 case

    AM I missing something... or is the answer not simply:

    =AVERAGEIF(B:B,H2,D:D)
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  11. #11
    Forum Contributor
    Join Date
    02-13-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: averaging every nth column working for all but 1 case

    I ended up using:

    =AVERAGEIF($A$1:$A$3480,"=1",$B$1:$B$3480)
    How could I modify instead of taking the average, I get the stdev of those numbers it included for each average?

  12. #12
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,244

    Re: averaging every nth column working for all but 1 case

    Hey BJ,

    See the attached where I've used the formula I presented above only changing the first formula. It also shows why you get a #Div/0 error.

    Every 21st Number Avg Cnt Stdev CSE.xlsx

+ 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. VBA Function averaging values for certain periods of dates not working anymore
    By slacknoise in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2014, 03:26 PM
  2. [SOLVED] Case Select not working
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-14-2010, 06:53 AM
  3. Case statement not working
    By nygwnj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2009, 01:41 AM
  4. Select Case not working
    By RadBrad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-31-2009, 01:11 AM
  5. Proper Case not working
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2008, 08:21 AM
  6. excel'03 how to convert a column from upper case to proper case
    By sharie palmer in forum Excel General
    Replies: 1
    Last Post: 01-30-2006, 07:55 PM
  7. How do I change a column in Excel from upper case to lower case?
    By Debbie Kennedy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-02-2005, 02:06 PM

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