+ Reply to Thread
Results 1 to 11 of 11

Averageif for only visible cells

  1. #1
    Forum Contributor
    Join Date
    07-21-2014
    Location
    Norway
    MS-Off Ver
    2016
    Posts
    230

    Averageif for only visible cells

    Hi

    I'm trying to make a averageif taking into account only cells that are visible. This is the formula =AVERAGEIF(HI20:HI9991,">0")
    I have tried with subtotal, sumproduct and so on, but apparently I don't get it to work.

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Averageif for only visible cells

    I don't think you can use AVERAGEIF in SUBTOTAL context, at least not yet...

    the below Array should do what you need?

    =AVERAGE(IF(SUBTOTAL(109,OFFSET(HI20,ROW(HI20:HI9991)-ROW(HI20),0))>0,HI20:HI9991))
    confirmed with CTRL + SHIFT + ENTER

    if the array is set correctly the above will appear encased within { } -- these cannot be added manually.

    edit:

    as a *tip* -- if you're doing lots of calculations based on filtered data it is, in my opinion, good practice to create a 1/0 flag (in a spare column) to denote row visibility, e.g.

    HZ20: =SUBTOTAL(3,A20)
    copied down

    you can then use this column (with criteria of 1) to isolate visible rows -- without needing to use expensive calcs like the above (i.e Volatile Array)
    Last edited by XLent; 05-23-2019 at 12:27 PM.

  3. #3
    Forum Contributor
    Join Date
    07-21-2014
    Location
    Norway
    MS-Off Ver
    2016
    Posts
    230

    Re: Averageif for only visible cells

    Great! thank you so much!

  4. #4
    Forum Contributor
    Join Date
    07-21-2014
    Location
    Norway
    MS-Off Ver
    2016
    Posts
    230

    Re: Averageif for only visible cells

    I tried the same and changing this formula:

    =SUMIF(HJ20:HJ9991,">1")

    to this one:

    =SUMPRODUCT(SUBTOTAL(109,OFFSET(HJ20,ROW(HJ20:HJ9991)-ROW(HJ20),0))>1,HJ20:HJ9991)

    but I just get 0...?

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Averageif for only visible cells

    Why not just

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

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Forum Contributor
    Join Date
    07-21-2014
    Location
    Norway
    MS-Off Ver
    2016
    Posts
    230

    Re: Averageif for only visible cells

    It doesn't work, I get 5.7 with that formula. I should get 741. It must take into account that it should be above 1 and not take into account hidden cells that are filtered
    Last edited by excelnabb; 05-23-2019 at 01:26 PM.

  7. #7
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Averageif for only visible cells

    Hi, sorry, just reading this...

    You're saying you've added the 1/0 {visible flag formula} to column HJ?

    If so you can then replace the Array with an AVERAGEIFS using new column [HJ] as the 2nd criteria (=1 - i.e. visible row)

    =AVERAGEIFS(HI20:HI9991,HI20:HI9991,">0",HJ20:HJ9991,1)

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Averageif for only visible cells

    Please upload the workbook so that we can see in context

  9. #9
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Averageif for only visible cells

    edit: if you want to SUM col HJ where > 1 and visible then the change is to coerce you boolean array:

    =SUMPRODUCT(--(SUBTOTAL(109,OFFSET(HJ20,ROW(HJ20:HJ9991)-ROW(HJ20),0))>1),HJ20:HJ9991)

    but I reiterate my earlier point - the fact you're doing multiple calcs using visible rows means, for efficiency, you should really add the single visible flag calc in a spare column
    with the above in place your calcs become trivial (and non-volatile) - e.g. AVERAGE calc (per prior post) whilst your SUM becomes a simple SUMIFS - i.e. SUMIFS(number_range,number_range,">1",visible_range,1)

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Averageif for only visible cells

    Quote Originally Posted by excelnabb View Post
    It doesn't work, I get 5.7 with that formula. I should get 741. It must take into account that it should be above 1 and not take into account hidden cells that are filtered
    One pragmatic solution would be to use a helper column that determined which rows to hide
    e.g.

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


    Then filter on he helper column and use the formula I gave you.

  11. #11
    Forum Contributor
    Join Date
    07-21-2014
    Location
    Norway
    MS-Off Ver
    2016
    Posts
    230

    Re: Averageif for only visible cells

    This one worked perfectly!
    =SUMPRODUCT(--(SUBTOTAL(109,OFFSET(HJ20,ROW(HJ20:HJ9991)-ROW(HJ20),0))>1),HJ20:HJ9991)
    thank you to you all!

+ 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. Copy Visible Date and Paste into Visible Cells only
    By vikas_newports in forum Excel General
    Replies: 14
    Last Post: 07-01-2020, 01:43 PM
  2. Copy-Paste formatting of visible cells to visible cells
    By hansaaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2018, 04:29 PM
  3. error trying to get averageif for visible cells only
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-05-2017, 07:34 AM
  4. [SOLVED] Using averageif when all cells are 0's
    By Chrisaep in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-23-2013, 12:35 PM
  5. [SOLVED] Copy/Pasting Values from visible cells (using autofilter) to visible cells
    By evakotsi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2012, 07:49 AM
  6. [SOLVED] changing a current mod (count unique visible cells ->count unique visible cells criteria
    By liranbo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2012, 03:58 AM
  7. Copy Visible cells and paste values only to visible target cells
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2010, 04:09 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