+ Reply to Thread
Results 1 to 10 of 10

how to incorporate an if then else function to an average formula

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-24-2008
    MS-Off Ver
    2007
    Posts
    139

    how to incorporate an if then else function to an average formula

    Is there a way to include an if then else function to an average formula that will skip cells with zero?

    I went into better detail in the attached example.
    Attached Files Attached Files
    Last edited by novice2430; 06-17-2009 at 02:22 PM.

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

    Re: how to incorporate an if then else function to an average formula

    one way to achieve this, without using arrays, would be to add a helper index adjacent to your values in B, say:

    A4: =IF($B4,MAX($A$3:$A3)+1,0)
    copy down for all rows
    You can then base your Average on the values in A such that:

    C4: 
    =IF($B4,SUMIF($A$4:$A4,">="&$A4-3+($B4<>0),$B$4:$B4)/COUNTIF($A$4:$A4,">="&A4-3+($B4<>0)),0)
    copy down for all rows
    Last edited by DonkeyOte; 06-14-2009 at 03:52 AM.

  3. #3
    Forum Contributor
    Join Date
    06-24-2008
    MS-Off Ver
    2007
    Posts
    139

    Re: how to incorporate an if then else function to an average formula

    I took this:


    =IF($B4,SUMIF($A$4:$A4,">="&$A4-3+($B4<>0),$B$4:$B4)/COUNTIF($A$4:$A4,">="&A4-3+($B4<>0)),0)
    And made this out of it:

    =IF($B4,SUMIF($A$4:$A4,">="&$A4-2+($B4<>0),$B$4:$B4),0)
    I notice that this adds the last two valid cells. How do I get it to subtract the last two valid cells?

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

    Re: how to incorporate an if then else function to an average formula

    Is this is a different question ? The first question implied you wanted to average (at most) the last three non-zero cells in the rolling range which was what the formula provided did (in conjunction with the helper index formulae in Column A)... what are you looking to do now exactly ?

  5. #5
    Forum Contributor
    Join Date
    06-24-2008
    MS-Off Ver
    2007
    Posts
    139

    Re: how to incorporate an if then else function to an average formula

    You're right it is different, but not totally different.
    I can't give an example because I'm writing from my phone, ill try to explain as clear as possible.

    I have calculations in column d on the same worksheet.
    The formula starts in D5 and is '=$C5-$C4. When zeros are present the calculations are thrown off,
    so like before I used column a as the index and tried to use this code:

    =IF($C4,SUMIF($A$4:$A5,">="&$A5-2+($C5<>0),$C$4:$C5),0)
    I'm trying to subtract but this code adds the two together.

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

    Re: how to incorporate an if then else function to an average formula

    Post a sample... I think you're saying you want to Sum all cells except the last two non-zero values, correct ?

  7. #7
    Forum Contributor
    Join Date
    06-24-2008
    MS-Off Ver
    2007
    Posts
    139

    Re: how to incorporate an if then else function to an average formula

    I've attached the sample
    Attached Files Attached Files

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

    Re: how to incorporate an if then else function to an average formula

    Either:

    D5: =IF($C5,$C5-INDEX($C$4:$C4,MATCH($A5-1,$A$4:$A4,0)),0)
    copied down

    or

    D5: =IF($C5,$C5-LOOKUP(2,1/($C$4:$C4<>0),$C$4:$C4),0)
    copied down

    if you keep using the key column in A as is presently set up then use the first approach shown.

  9. #9
    Forum Contributor
    Join Date
    06-24-2008
    MS-Off Ver
    2007
    Posts
    139

    Re: how to incorporate an if then else function to an average formula

    Thank you for all the help. You really know excel.

+ 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