+ Reply to Thread
Results 1 to 14 of 14

How to AVERAGEIF not using a range of cells?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-12-2020
    Location
    USA
    MS-Off Ver
    2013
    Posts
    133

    How to AVERAGEIF not using a range of cells?

    I've got a formula that will pull in a number. Sometimes that number will be 0. I want to get the average of the items not counting any zeroes. I want this =AVERAGEIF({formula1, formula2, etc},"<>0"). I haven't been able to figure out a way to feed AVERAGEIF individual values to average. I would think that =AVERAGEIF({3,7,0,4},"<>0") should be possible but again I haven't figured out how to make it work. BTW, the answer to the example should be 4.666 (i.e. 14/3). TIA
    Last edited by bird333; 06-18-2023 at 08:45 PM.

  2. #2
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: How to AVERAGEIF not using a range of cells?

    =AVERAGEIF({3,7,0,4},"<>0") is not possible, because AVERAGEIF needs a range and {3,7,0,4} is not a range but an array.

    If you want to code the AVARAGE with an (hardcoded) array you can try: =LET(t,{3,7,0,4},AVERAGE(FILTER(t,t<>0)))
    Last edited by HansDouwe; 06-09-2023 at 12:54 PM.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,423

    Re: How to AVERAGEIF not using a range of cells?

    You won't be able to use LET of FILTER functions if you are still using XL2013, as your profile states. Instead, you could use this formula:

    =SUM(IF({3,7,0,4}<>0,{3,7,0,4}))/COUNT(IF({3,7,0,4}<>0,1))

    which will average the numbers in the array which are not zero.

    Hope this helps.

    Pete

  4. #4
    Forum Contributor
    Join Date
    06-12-2020
    Location
    USA
    MS-Off Ver
    2013
    Posts
    133

    Re: How to AVERAGEIF not using a range of cells?

    Well of course the formula doesn't work when I put my formula in for the numbers in the example. I.e. =SUM(IF({my formula,my formula,my formula,my formula}<>0,{my formula,my formula,my formula,my formula}))/COUNT(IF({my formula,my formula,my formula,my formula}<>0,1)). The error I get seems to indicate that excel thinks I'm trying to type text instead of a formula. I tried adding "+0" to my formula to coerce excel but it didn't help. My formula does use a custom function from an add-on. I don't know if that causing problems.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: How to AVERAGEIF not using a range of cells?

    Perhaps it is just me -- who would simply put the individual formulas into cells in a helper range and then use =AVERAGEIF(helper_range,"<>0"). It seems to me we are unnecessarily trying to tie ourselves into knots to avoid the helper range.

    If I were absolutely forbidden from using the helper range, I think I would use something like =AVERAGE(IF(formula1<>0,formula1,"text"),IF(formula2<>0,formula2,"text"),...). The IF() functions inside of the AVERAGE() perform each individual calculation and, when that calculation results in 0, replaces the number with a text string, which the AVERAGE() function will ignore when it computes the average.

    Would something like that work for you?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Contributor
    Join Date
    06-12-2020
    Location
    USA
    MS-Off Ver
    2013
    Posts
    133

    Re: How to AVERAGEIF not using a range of cells?

    Quote Originally Posted by MrShorty View Post
    Perhaps it is just me -- who would simply put the individual formulas into cells in a helper range and then use =AVERAGEIF(helper_range,"<>0"). It seems to me we are unnecessarily trying to tie ourselves into knots to avoid the helper range.

    If I were absolutely forbidden from using the helper range, I think I would use something like =AVERAGE(IF(formula1<>0,formula1,"text"),IF(formula2<>0,formula2,"text"),...). The IF() functions inside of the AVERAGE() perform each individual calculation and, when that calculation results in 0, replaces the number with a text string, which the AVERAGE() function will ignore when it computes the average.

    Would something like that work for you?
    Thanks for the response. Average doesn't seem to ignore 'text'. The formula gives a #VALUE! error when one of the IF functions returns "text".

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,742

    Re: How to AVERAGEIF not using a range of cells?

    If I understand correctly perhaps this
    Formula: copy to clipboard
    =AVERAGE(IF({3,7,0,4}<>0,{3,7,0,4}))
    It returns 4.666 at my end.
    Dave

  8. #8
    Forum Contributor
    Join Date
    06-12-2020
    Location
    USA
    MS-Off Ver
    2013
    Posts
    133

    Re: How to AVERAGEIF not using a range of cells?

    Quote Originally Posted by FlameRetired View Post
    If I understand correctly perhaps this
    Formula: copy to clipboard
    =AVERAGE(IF({3,7,0,4}<>0,{3,7,0,4}))
    It returns 4.666 at my end.
    Thanks but when I replace the numbers with my formula that returns a number, it doesn't work. Same problem that I report in post #4.
    Last edited by bird333; 06-14-2023 at 11:16 PM.

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,742

    Re: How to AVERAGEIF not using a range of cells?

    Actually that can be shortened to
    Formula: copy to clipboard
    =AVERAGE(IF({3,7,0,4},{3,7,0,4}))

  10. #10
    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. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,006

    Re: How to AVERAGEIF not using a range of cells?

    Time to have a look at the data rather than guessing. What is the formula that generated the numbers? Is it in fact generating text?

    There are instructions at the top of the page explaining how to attach your sample workbook (yellow banner: HOW TO ATTACH YOUR SAMPLE WORKBOOK). Screenshots are of little practical use as we cannot manipulate them.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    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.

  11. #11
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: How to AVERAGEIF not using a range of cells?

    Average doesn't seem to ignore 'text'. The formula gives a #VALUE! error when one of the IF functions returns "text".
    In the spirit of learning new things every day, I must have never encountered this behavior before. I am surprised.

    Here's what I tried instead.

    Average is sum/count, so I tried something based on that basic definition.

    1) Zero values have no impact on the sum, so a simple SUM(formula1,formula2,formula3,formula4) is enough to get the sum.
    2) The count of non-zero values is trickier. First I reduce each formula to a value of 1 or 0. I can use the SIGN() function for this (or ABS(SIGN()) if the formulas can return negative values). SIGN(formula1),SIGN(formula2),...
    3) A simple SUM() function can now add up the results of the SIGN() functions to get the count SUM(SIGN(formula1),SIGN(formula2),...)
    4) The average is the ratio of step 1 and step 3 =SUM(formula1,formula2,...)/SUM(SIGN(formula1),SIGN(formula2),...)

    That should work. The only problem I can foresee with this approach is if your formulas are subject to floating point errors so that what should be exactly 0 is not exactly 0. In that case, some adjustment will need to be made to force the "should be exactly 0" values to be "exactly 0."

  12. #12
    Forum Contributor
    Join Date
    06-12-2020
    Location
    USA
    MS-Off Ver
    2013
    Posts
    133

    Re: How to AVERAGEIF not using a range of cells?

    Quote Originally Posted by MrShorty View Post
    In the spirit of learning new things every day, I must have never encountered this behavior before. I am surprised.

    Here's what I tried instead.

    Average is sum/count, so I tried something based on that basic definition.

    1) Zero values have no impact on the sum, so a simple SUM(formula1,formula2,formula3,formula4) is enough to get the sum.
    2) The count of non-zero values is trickier. First I reduce each formula to a value of 1 or 0. I can use the SIGN() function for this (or ABS(SIGN()) if the formulas can return negative values). SIGN(formula1),SIGN(formula2),...
    3) A simple SUM() function can now add up the results of the SIGN() functions to get the count SUM(SIGN(formula1),SIGN(formula2),...)
    4) The average is the ratio of step 1 and step 3 =SUM(formula1,formula2,...)/SUM(SIGN(formula1),SIGN(formula2),...)

    That should work. The only problem I can foresee with this approach is if your formulas are subject to floating point errors so that what should be exactly 0 is not exactly 0. In that case, some adjustment will need to be made to force the "should be exactly 0" values to be "exactly 0."
    This formula works. Anybody know why the other formulas don't?
    Last edited by bird333; 06-17-2023 at 12:33 AM.

  13. #13
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: How to AVERAGEIF not using a range of cells?

    The AVERAGE function ignores TEXT-VALUES, but does not ignore zero-values.

    I'll wait for an example-sheet of the OP before I post a solution.
    Attached Files Attached Files

  14. #14
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: How to AVERAGEIF not using a range of cells?

    @HansDouwe: You are correct when the average values are in cells and you are using a reference or references to those cells inside of the AVERAGE() function. I have always done my averages this way and never had trouble ignoring text values.

    However, remember that the OP, for some reason known only to the OP, wants to avoid at all costs storing the values to be averaged in cells. They want to nest the formulas that calculate the values to be averaged inside of the AVERAGE() function -- while also ignoring those cases where the formula returns 0. When you nest something like IF(formula=0,"text",formula) inside of the AVERAGE() function, an error is triggered.

+ 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. AVERAGEIF with dynamic range?
    By ceght in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-17-2017, 08:17 AM
  2. [SOLVED] Averageif(range,monthcriteria,[average range])???
    By athyeh in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-19-2013, 12:09 PM
  3. Using averageif with dynamic range
    By davetcw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2013, 07:17 PM
  4. [SOLVED] averageif for date range
    By tbaron in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-14-2013, 07:48 PM
  5. Excel 2007 : AVERAGEIF range function
    By Jerseynjphillypa in forum Excel General
    Replies: 1
    Last Post: 07-16-2012, 10:45 AM
  6. Excel 2007 : Using YEAR() of a range in AVERAGEIF
    By qaliq in forum Excel General
    Replies: 2
    Last Post: 11-01-2011, 09:17 AM
  7. AverageIf across a range of sheets
    By Ducjes in forum Excel General
    Replies: 4
    Last Post: 07-06-2010, 03:40 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