+ Reply to Thread
Results 1 to 15 of 15

averageif across worksheets

  1. #1
    Registered User
    Join Date
    09-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    22

    averageif across worksheets

    Hi,

    I have several worksheets that are all formatted exactly the same and then one worksheet at the back with various kinds of summary and total data.

    An example spreadsheet is attached.

    Each worksheet, except the summary one, represents the sales and costs of an individual store from January through July 2013.

    In the Summary worksheet I'm trying to get the average sales and costs for the stores.

    I'm using the "averageif" function because one of the stores is closed down during the year and has $0 sales. I'd like to ignore these.

    I can't get the "averageif" to work -- I keep getting "value". Please see specifically the yellow shaded cells in the "Summary" tab attached.

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: averageif across worksheets

    Are those the REAL sheet names?

    The reason I ask is if I write you a formula based on THOSE sheet names and it doesn't work in your real file because of the sheet names then I'll be ______!
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    09-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: averageif across worksheets

    Hi Biff -- those unfortunately aren't the real sheet names. There are also about 15 more sheets. I think I could adapt what you write, however.

  4. #4
    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
    52,938

    Re: averageif across worksheets

    averageif() wont work across worksheets

    Asa long as the "closed" store has no entries, this should work...
    =AVERAGE(Store1:Store3!C6)
    or this
    =SUM(Store1:Store3!C6)/COUNT(Store1:Store3!C6)
    (I know Tony will have a better formula that will ignore 0, but my brain just shut down )
    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

  5. #5
    Registered User
    Join Date
    09-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: averageif across worksheets

    Thanks but a lot of my data will just have the 0s in it. I would love to use the average formula but it just won't work

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: averageif across worksheets

    Try this...

    On the Summary sheet enter this formula in C6:

    =SUM(Store1:Store3!C6)/(FREQUENCY(Store1:Store3!C6,-0.000001)+INDEX(FREQUENCY(Store1:Store3!C6,0),2))

    Copy down to C7 then across to I6:I7.

  7. #7
    Registered User
    Join Date
    09-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: averageif across worksheets

    Thanks - but what are the Index and Frequency functions doing?

  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
    52,938

    Re: averageif across worksheets

    Yeah Tony..."what are the Index and Frequency functions doing? "

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: averageif across worksheets

    We know that an average is a sum divided by a count.

    So, we get the sum:

    SUM(Store1:Store3!C6)

    And then we use the FREQUENCY function(s) to get the count of non-zero numbers.

    The FREQUENCY function performs a series of "count if" operations based on the arguments provided.

    The first FREQUENCY function:

    FREQUENCY(Store1:Store3!C6,-0.000001)

    Performs these "count ifs":

    Count if Store1:Store3!C6 is <= -0.000001
    Count if Store1:Store3!C6 is > -0.000001

    The second FREQUENCY function:

    FREQUENCY(Store1:Store3!C6,0)

    Performs these "count ifs":

    Count if Store1:Store3!C6 is <= 0
    Count if Store1:Store3!C6 is > 0

    In order to get the correct average we need to count both the negative numbers and the numbers that are >0 in the data.

    We do that by adding together:

    Count if Store1:Store3!C6 is <= -0.000001
    Count if Store1:Store3!C6 is > 0

    Since the second FREQUENCY function performs 2 "count ifs", and the one we need is the second one, we use the INDEX function to return the second "count if":

    INDEX(FREQUENCY(Store1:Store3!C6,0),2) = Count if Store1:Store3!C6 is > 0

    So, to get the average across the sheets and ignore the 0 values:

    =SUM(Store1:Store3!C6)/(FREQUENCY(Store1:Store3!C6,-0.000001)+INDEX(FREQUENCY(Store1:Store3!C6,0),2))

    You might think: WTH, why do we need to use such a convoluted formula to do this?

    Well, the answer is because MS didn't make this easy for us. They didn't give the AVERAGEIF function the ability to calculate across multiple sheets without using extreme "trickeration". So, we come up with these convoluted (but "slick") alternatives.

  10. #10
    Registered User
    Join Date
    09-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    22

    Cool Re: averageif across worksheets

    Awesome! This is great. Thank you very much. Sorry for having to ask but I tried to google the Frequency and Index functions and I still wasn't getting it. I can't put formulas in my work that I don't understand. Thanks again.




    Quote Originally Posted by Tony Valko View Post
    We know that an average is a sum divided by a count.

    So, we get the sum:

    SUM(Store1:Store3!C6)

    And then we use the FREQUENCY function(s) to get the count of non-zero numbers.

    The FREQUENCY function performs a series of "count if" operations based on the arguments provided.

    The first FREQUENCY function:

    FREQUENCY(Store1:Store3!C6,-0.000001)

    Performs these "count ifs":

    Count if Store1:Store3!C6 is <= -0.000001
    Count if Store1:Store3!C6 is > -0.000001

    The second FREQUENCY function:

    FREQUENCY(Store1:Store3!C6,0)

    Performs these "count ifs":

    Count if Store1:Store3!C6 is <= 0
    Count if Store1:Store3!C6 is > 0

    In order to get the correct average we need to count both the negative numbers and the numbers that are >0 in the data.

    We do that by adding together:

    Count if Store1:Store3!C6 is <= -0.000001
    Count if Store1:Store3!C6 is > 0

    Since the second FREQUENCY function performs 2 "count ifs", and the one we need is the second one, we use the INDEX function to return the second "count if":

    INDEX(FREQUENCY(Store1:Store3!C6,0),2) = Count if Store1:Store3!C6 is > 0

    So, to get the average across the sheets and ignore the 0 values:

    =SUM(Store1:Store3!C6)/(FREQUENCY(Store1:Store3!C6,-0.000001)+INDEX(FREQUENCY(Store1:Store3!C6,0),2))

    You might think: WTH, why do we need to use such a convoluted formula to do this?

    Well, the answer is because MS didn't make this easy for us. They didn't give the AVERAGEIF function the ability to calculate across multiple sheets without using extreme "trickeration". So, we come up with these convoluted (but "slick") alternatives.

  11. #11
    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
    52,938

    Re: averageif across worksheets

    you'r welcome. If this answered your question, please take a moment to mark the thread as "solved" - it helps keep things neat and tidy lol, and consider adding the reputation to those that helped (see points 2 & 3 below)

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: averageif across worksheets

    You're welcome. Thanks for the feedback!

  13. #13
    Registered User
    Join Date
    09-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: averageif across worksheets

    done -- marked as solved. I tried to "add reputation" to Tony but it said I had to "spread the reputation around"...or something like that. I guess he had helped me previously and I added then, but not enough to others (although i don't use the forum frequently).

  14. #14
    Registered User
    Join Date
    10-29-2014
    Location
    San Diego, CA
    MS-Off Ver
    2010
    Posts
    1

    Red face Re: averageif across worksheets

    Quote Originally Posted by Tony Valko View Post
    Try this...

    On the Summary sheet enter this formula in C6:

    =SUM(Store1:Store3!C6)/(FREQUENCY(Store1:Store3!C6,-0.000001)+INDEX(FREQUENCY(Store1:Store3!C6,0),2))

    Copy down to C7 then across to I6:I7.
    Tony - This solution worked great for me. I only needed to average the contents of a single cell across multiple sheets and this was by far the simplest solution compared to all the VBA scripts being suggested on other forums I checked. Thanks

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: averageif across worksheets

    Good deal. Thanks for the feedback!

+ 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. [SOLVED] Averageif
    By edmundo1971 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-03-2013, 09:48 AM
  2. AVERAGEIF (Multiple Worksheets)
    By graybush in forum Excel General
    Replies: 1
    Last Post: 11-02-2011, 09:59 PM
  3. averageif
    By Ecel12 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 08-25-2011, 08:21 AM
  4. averageif
    By name in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-04-2006, 12:30 PM
  5. averageif
    By rudy in forum Excel General
    Replies: 5
    Last Post: 04-27-2006, 06:20 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