Closed Thread
Results 1 to 15 of 15

Averaging and Complex Counting of Cells Where a Specific Column and Row Header Intersect

  1. #1
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Averaging and Complex Counting of Cells Where a Specific Column and Row Header Intersect

    20pt Commercial Thread Available @ http://www.excelforum.com/showthread.php?t=944704


    The original request below is out of date. Thus, I have provided an update here and in the final post:

    Thank you all in advance!

    Basically I need 4 formulas that do the following to an array of data similar to the one below.

    1. Average all data associated with a column that contains the word "pig" in the heading. Hence, this must average even the column below called "Pigcow."
    -Potentially solved with array formula: =AVERAGE(TRANSPOSE(IF(ISNUMBER(SEARCH("pig",B2:F2)),IF(LEN(B3:F5)>0,B3:F5))))

    2. Do the same thing as the above formula (i.e. only looking at rows that contain "pig" somewhere in the header) and count all values that are 4 and 5 and divide that number by the number of total values (e.g. 1s, 2s, 3s, 4s, & 5s). Hence giving me the percentage of 4s and 5s in the data.
    -Potentially solved with array formula: =SUM(IF(ISNUMBER(SEARCH("pig",B2:F2))*(B3:F5>3),1,0))/SUM(IF(ISNUMBER(SEARCH("pig",B2:F2))*(B3:F5>=1),1,0))

    3. Calculate an average like in point 1 but this time only average things where columns contain "pig" within the text (same as before) and intersect with rows that have a label equal to "happy." The look up for the rows does not need to search within the text. The full cell contents will always be what I am looking up (e.g. Happy)
    -not solved

    4. Do the same thing as point 3 above but this time count things like was request in point 2. Thus, count 4s and 5s where the columns containing "pig" intersect with "happy" rows and divide that by the total number of data points (e.g. 1s, 2s, 3s, 4s, & 5s) contained in the same intersecting spots.
    -not solved

    I have posted in the formula forum if you are curious to see others partial solutions. My request evolved over a couple days and has not been fully solved.
    http://www.excelforum.com/excel-form...55#post3351055

    Thank you all for your help. I look forward to a solution!

    Please note: The above formulas must properly skip blanks written by another formula that returns a value of "".

    col1 col2 col3 col4 col5 col6
    sad Pig Pigcow Cow Cow Pigcow
    Happy 1 3 4 2 5
    Sad 4 4 3 1
    Happy 5 3 4 5


    ---------------------------------

    Hello everyone,

    Can anyone help me create a formula that will reference the entire table below but average only the three columns headed by the letter A? It needs to not count blanks as 0.

    My full dataset contains many columns and rows and I would love to be able to use formulas to average just those columns headed by A, B, C, D, etc.

    A A A B B B
    1 1 1 1 1 9
    3 2 8 7
    2 4 5 8 8
    1 5 2 3 2 0
    4 1 4 4 8 7
    2 3 2 4 5 4
    2 2 1 2 0

    Thank you in advance for your help.

    -Darwin
    Last edited by darwin003; 08-04-2013 at 05:53 PM. Reason: Expanded issue to TEXT contained in header row, not just the entire contents of the header row and a blank cell related issue

  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: Averaging Multiple Columns Based on Header Row

    One way:

    =SUMPRODUCT((A1:F1="A")*A2:F8) / SUMPRODUCT((A1:F1="A")*(A2:F8<>""))
    _________________
    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
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Averaging Multiple Columns Based on Header Row

    Quote Originally Posted by JBeaucaire View Post
    One way:

    =SUMPRODUCT((A1:F1="A")*A2:F8) / SUMPRODUCT((A1:F1="A")*(A2:F8<>""))
    Thank you so much for the help JBeaucaire!

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

    Re: Averaging Multiple Columns Based on Header Row

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above and mark this thread as SOLVED. Thanks.

  5. #5
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Averaging Multiple Columns Based on Header Row

    Quote Originally Posted by JBeaucaire View Post
    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above and mark this thread as SOLVED. Thanks.
    Thank you again JBeaucaire for showing me how to mark a thread as solved. I hope the rep was worth the trouble

    This also let me know how to UNsolve my thread and ask another question that builds on the logic you have already helped me with.

    Basically what I need to do now is average multiple columns based on TEXT that is contained in the header row. Hence, not just the entire cell contents of the header row.

    Thus, in the example below, I would like to be able to average all three rows of data that correspond to columns that contain the string "Pig" (e.g. col 1,2,3, & 6)

    Thank you all in advance, this forum truly helps me learn, saves me days of time, and keeps me from getting fired!!
    col1 col2 col3 col4 col5 col6
    PigCow Pig Pigcow Cow Cow Pigcow
    1 1 3 4 2 5
    2 4 4 3 5 1
    3 5 3 4 5 5

  6. #6
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: Averaging Multiple Columns Based on Partial String of Text Contained in Header Row

    Add ISNUMBER(SEARCH("pig" in JB's formula;

    =SUMPRODUCT(ISNUMBER(SEARCH("pig",A1:F1))*A2:F8) / SUMPRODUCT(ISNUMBER(SEARCH("pig",A1:F1))*(A2:F8<>""))
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  7. #7
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Averaging Multiple Columns Based on Partial String of Text Contained in Header Row

    Quote Originally Posted by Haseeb A View Post
    Add ISNUMBER(SEARCH("pig" in JB's formula;

    =SUMPRODUCT(ISNUMBER(SEARCH("pig",A1:F1))*A2:F8) / SUMPRODUCT(ISNUMBER(SEARCH("pig",A1:F1))*(A2:F8<>""))
    Thanks man.

    I was using search but didn't have the isnumber part.

    I still don't really understand what that is really doing in the formula but at least this solves my problems!

  8. #8
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Averaging Multiple Columns Based on Partial String of Text Contained in Header Row

    Sigh... it worked on my test data but not on the real data.

    I isolated the problem to the fact that blank cells in my data are generated by an hlookup formula that reads a previous formula that turns 0's into blanks via something like if(A1=0,"",A1).

    For some reason this screws up the formula that Haseeb was kind enough to share with me.

    Deleting the blank cells manually makes the formula work perfectly but that isn't an option I can use.

    Any idea how to fix this excel gods?

  9. #9
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Averaging Multiple Columns Based on Partial String of Text Contained in Header Row

    Try this array formula(confirm Control+Shift+Enter)
    =AVERAGE(TRANSPOSE(IF(ISNUMBER(SEARCH("pig",A1:F1)),IF(LEN(A2:F8)>0,A2:F8))))
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  10. #10
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Averaging Multiple Columns Based on Partial String of Text Contained in Header Row

    Quote Originally Posted by RobertMika View Post
    Try this array formula(confirm Control+Shift+Enter)
    =AVERAGE(TRANSPOSE(IF(ISNUMBER(SEARCH("pig",A1:F1)),IF(LEN(A2:F8)>0,A2:F8))))
    This works wonderfully on my test data and real data. Thank you so much

    So now I have two final question! Sorry for not asking these all at once, I didn't see them coming.

    How can I take RobertMika's great formula above and have it only average data in columns that contain the string "pig" as before, but now only where those "pig" columns intersect with "happy" rows. The row lookup part should only look for the complete cell to be named "happy." It does not need to look within the string like the column part.

    Then, how can I modify this formula (no longer averaging anything) to count the number of 4s and 5s contained in the chosen intersecting cells and divide the result by the number of total numbers (e.g. 1s,2s,3s,4s,&5s). Hence, giving me the percentage of 4s and 5s. -I got this working using RobertMika's formula for just the columns and an overall count but am having a hard time making it work for where row's intersect columns and for counting only cells with a specific number.

    I thought I could just change AVERAGE to COUNT in the formula below and change the bold par of the formula below to "=1" but that didn't work. Interestingly, I can remove that bold part from the formula and it doesn't seem to impact it working at all.

    =AVERAGE(TRANSPOSE(IF(ISNUMBER(SEARCH("pig",A1:F1)),IF(LEN(A2:F8)>0,A2:F8))))[/QUOTE]

    Both again need to skip blanks.

    Thank you again everyone for the help and especially for those who are replying! I know how to use these formulas in pieces but I'm still trying to wrap my head around getting them to all work in conjunction. Hence, my plea for help

    col1 col2 col3 col4 col5 col6
    sad Pig Pigcow Cow Cow Pigcow
    Happy 1 3 4 2 5
    Sad 4 4 3 1
    Happy 5 3 4 5
    Last edited by darwin003; 08-04-2013 at 11:58 AM.

  11. #11
    Registered User
    Join Date
    12-21-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Averaging Multiple Columns Based on Partial String of Text Contained in Header Row

    20pt Commercial Thread Available @ http://www.excelforum.com/showthread.php?t=944704


    I tried to clean things up a bit for anyone seeking information about what I am attempting to do and have solved so far with the help of the amazing

    Thank you all in advance!

    Basically I need 4 formulas that do the following to an array of data similar to the one below.

    1. Average all data associated with a column that contains the word "pig" in the heading. Hence, this must average even the column below called "Pigcow."
    -Potentially solved with array formula: =AVERAGE(TRANSPOSE(IF(ISNUMBER(SEARCH("pig",B2:F2)),IF(LEN(B3:F5)>0,B3:F5))))

    2. Do the same thing as the above formula (i.e. only looking at rows that contain "pig" somewhere in the header) and count all values that are 4 and 5 and divide that number by the number of total values (e.g. 1s, 2s, 3s, 4s, & 5s). Hence giving me the percentage of 4s and 5s in the data.
    -Potentially solved with array formula: =SUM(IF(ISNUMBER(SEARCH("pig",B2:F2))*(B3:F5>3),1,0))/SUM(IF(ISNUMBER(SEARCH("pig",B2:F2))*(B3:F5>=1),1,0))

    3. Calculate an average like in point 1 but this time only average things where columns contain "pig" within the text (same as before) and intersect with rows that have a label equal to "happy." The look up for the rows does not need to search within the text. The full cell contents will always be what I am looking up (e.g. Happy)
    -not solved

    4. Do the same thing as point 3 above but this time count things like was request in point 2. Thus, count 4s and 5s where the columns containing "pig" intersect with "happy" rows and divide that by the total number of data points (e.g. 1s, 2s, 3s, 4s, & 5s) contained in the same intersecting spots.
    -not solved

    I have posted in the formula forum if you are curious to see others partial solutions. My request evolved over a couple days and has not been fully solved.
    http://www.excelforum.com/excel-form...55#post3351055

    Thank you all for your help. I look forward to a solution!

    Please note: The above formulas must properly skip blanks written by another formula that returns a value of "".

    col1 col2 col3 col4 col5 col6
    sad Pig Pigcow Cow Cow Pigcow
    Happy 1 3 4 2 5
    Sad 4 4 3 1
    Happy 5 3 4 5
    Last edited by darwin003; 08-04-2013 at 05:52 PM.

  12. #12
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,366

    Re: Averaging and Complex Counting of Cells Where a Specific Column and Row Header Interse

    i think you should just add another validation for "happy"

    =AVERAGE(TRANSPOSE(IF(ISNUMBER(SEARCH("pig",B2:F2))*(A3:A5="happy"),IF(LEN(B3:F5)>0,B3:F5)))) -same goes with the #4 formula
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  13. #13
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Averaging and Complex Counting of Cells Where a Specific Column and Row Header Interse

    No really need for TRANSPOSE
    =AVERAGE(IF(A2:A7="Happy",IF(ISNUMBER(SEARCH("pig",B1:F1)),IF(LEN(B2:F7)>0,B2:F7))))
    Confirm Control+Shift+Enter

    or
    =AVERAGE(IF(A2:A7="Happy",IF(ISNUMBER(SEARCH("pig",B1:F1)),IF(NOT(ISBLANK(B2:F7)),B2:F7))))

    For the pigcow/happy

    For pig/happy only
    =AVERAGE(IF(A2:A7="Happy",IF(LEN(B1:F1)=LEN("pig"),IF(ISNUMBER(SEARCH("pig",B1:F1)),IF(LEN(B2:F7)>0,B2:F7)))))

    Only moderators and admins have access to comercial section.
    Last edited by RobertMika; 08-05-2013 at 12:27 AM.

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

    Re: Averaging and Complex Counting of Cells Where a Specific Column and Row Header Interse

    ...Only moderators and admins have access to comercial section.
    And forum Gurus. The note he added was at my behest, normally duplicate posts are frowned up, but in this instance it's more of a cross-post, so the link is intended to comply with forum rules regarding cross-posting.

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Averaging and Complex Counting of Cells Where a Specific Column and Row Header Interse

    Thread posted in Commercial services subforum.

    This thread is closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formula help (averaging multiple columns)
    By xceller8 in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 07-06-2013, 10:06 PM
  2. [SOLVED] Sort multiple columns based on column header
    By Langer101 in forum Excel Programming / VBA / Macros
    Replies: 39
    Last Post: 01-09-2013, 09:55 AM
  3. Replies: 2
    Last Post: 10-13-2012, 03:30 AM
  4. Replies: 0
    Last Post: 05-12-2011, 04:24 PM
  5. Excel 2007 : Averaging multiple columns row by row
    By UtahDude in forum Excel General
    Replies: 1
    Last Post: 03-24-2010, 05:31 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