+ Reply to Thread
Results 1 to 4 of 4

IF Then - using 12 months - ongoing average

  1. #1
    Registered User
    Join Date
    03-07-2009
    Location
    Birmingham, Al USA
    MS-Off Ver
    Excel 2003
    Posts
    44

    IF Then - using 12 months - ongoing average

    This is pretty basic but it’s the best that I could do not knowing VBA or an easier way. I hope someone can help in making it better. The formula works but under very strict conditions. The spreadsheet has columns for all 12 months, a yearly total and an average column. The “If – Then” is for the average column for entire year. No matter what the month it will calculate the average using the appropriate number of months to divide by, now here’s the catch; each previous month has to have a number greater than “0” and luckily I have but if a previous month has a "0" it blows the formula out of the water.
    I had to split the into IF-Then into two sections because of the embedding limitations so when I have a lot of items that I need to do this for you can see I am having to reproduce this formula multiple times and tracking gets a little confusing.
    Jan – Column C Feb – Column D Mar – Column E Apr – Column F May – Column G
    Jun – Column H Jul – Column I Aug – Column J C Sept – Column K Oct – Column L
    Nov – Column M Dec – Column N

    Jan thru June: (Cell V4)
    =IF((AND($C$19>0,$D$19<=0)),$C$19,IF((AND($D$19>0,$E$19<=0)),(($C$19+$D$19)/2),IF((AND($E$19>0,$F$19<=0)),(($C$19+$D$19+$E$19)/3),IF((AND($F$19>0,$G$19<=0)),(($C$19+$D$19+$E$19+$F$19)/4),IF((AND($G$19>0,$H$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19)/5),IF((AND($H$19>0,$I$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19)/6),0))))))

    July thru Dec: (Cell V5)
    =IF((AND($I$19>0,$J$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19+$I$19)/7),IF((AND($J$19>0,$K$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19+$I$19+$J$19)/8),IF((AND($K$19>0,$L$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19+$I$19+$J$19+$K$19)/9),IF((AND($L$19>0,$M$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19+$I$19+$J$19+$K$19+$L$19)/10),IF((AND($M$19>0,$N$19<=0)),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19+$I$19+$J$19+$K$19+$L$19+$M$19)/11),IF(($N$19>0),(($C$19+$D$19+$E$19+$F$19+$G$19+$H$19+$I$19+$J$19+$K$19+$L$19+$M$19+$N$19)/12),0))))))

    Average Column: (Cell I19 is the cell for July Average for this particular Item)
    =IF(I19>0,V5,V4)
    Attached Files Attached Files
    Last edited by harleypop; 03-08-2009 at 01:45 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: IF Then - using 12 months - ongoing average

    Could you just post up your workbook so we don 't have to waste time reconstructing it to test...?

    GO ADVANCED and click on the paperclip icon.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: IF Then - using 12 months - ongoing average

    Given the 0 issue the area of interest thus becomes the rows above and how they are populated... for ex... I presume row 19 is the sum of rows 2:18, are these rows populated with 0's for future months ? If yes, would you EVER have 0's for all rows as valid results ?

    I would be inclined to alter the SUM in 19 such that a number is only displayed if there are actuals in preceding rows:

    B19: =IF(AND(COUNT(B2:B18),COUNTIF(B2:B18,"<>0")),SUM(B2:B18),"")
    copied to M19

    You can then just use a standard AVERAGE

    P19: AVERAGE(B19:M19)


    FYI:

    If 0 were not a potentially valid historical result the traditional approach would be one of:

    =AVERAGE(IF(B19:M19,B19:M19))
    entered with CTRL + SHIFT + ENTER

    or

    =AVERAGE(B19:INDEX(B19:M19,LOOKUP(2,1/(B19:M19<>0),COLUMN(B19:M19)-1)))

    (either way I make the Avg in your sample 4717.72)

  4. #4
    Registered User
    Join Date
    03-07-2009
    Location
    Birmingham, Al USA
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: IF Then - using 12 months - ongoing average

    [QUOTE=

    =AVERAGE(B19:INDEX(B19:M19,LOOKUP(2,1/(B19:M19<>0),COLUMN(B19:M19)-1)))

    [/QUOTE]

    This works great for what I was doing, yes I noticed later that my cut and paste into an example spreadsheet gave the wrong result, my actual spreadsheet was to big to post.

    Thank you DonkeyOte.

+ 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