+ Reply to Thread
Results 1 to 8 of 8

compute an average if certain conditions are satisfied

  1. #1
    Registered User
    Join Date
    03-04-2017
    Location
    NJ
    MS-Off Ver
    Excel for Mac Version 15.31
    Posts
    75

    compute an average if certain conditions are satisfied

    Hi everyone,
    I have a problem that I would really appreciate your help. I spent hours googling online but I couldn't find a solution that best fits the problem I'm having.

    Basically, in this example, I have 5 columns (i.e., Names, Selection 1, Selection 2, Subject, and Grade), and I have two students, Mary and James. Mary and James have grades for all 4 subjects: Language, Mathematics, Reading, and Science.

    I want to compute an average grade of whichever two subjects my students wanted to count towards their average. So for Mary, I want to write a function that allows me to compute an average grade of her selection, which includes Language and Reading, and for James, I want to compute an average grade of his selection, which includes Mathematics and Science, so that the end result I would get an average score of 75 (average of 90 and 60) for Mary, and an average score of 60 (average of 50 and 70) for James.
    How do I do that? Attached is my excel workbook to make things simpler. Many thanks for your help.

    Names Selection1 Selection2 Subject Grade
    Mary Language Reading Language 90
    Mary Language Reading Mathematics 50
    Mary Language Reading Reading 60
    Mary Language Reading Science 70
    James Mathematics Science Language 80
    James Mathematics Science Mathematics 50
    James Mathematics Science Reading 60
    James Mathematics Science Science 70
    Attached Files Attached Files
    Last edited by anita2017; 03-04-2017 at 12:49 PM.

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: compute an average if certain conditions are satisfied

    Attach a sample workbook. (Not a picture!)
    Make sure there is just enough data to demonstrate your need. Include a BEFORE (original) sheet and an AFTER (required output) sheet in the workbook if needed to show the process you're trying to complete or automate.
    Make sure your desired results are shown, mock them up manually if necessary. Remember, it should reflect original structure of your data.
    Remember to desensitize the data.
    Note:
    • Please do not attach password protected workbooks/worksheets
    • Please do not attach file(s) from exterior servers
    • Please do not attach file(s) with enabled any Workbook Open/Autorun macros!

    20 rows of data is enough (probably)

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If link is not from FORUM server you have to wait until someone will want to watch the file from an external server.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,004

    Re: compute an average if certain conditions are satisfied

    See attached:

    Formula

    =SUMPRODUCT(($E$2:$E$9)*($A$2:$A$9=$G2)*($D$2:$D$9=OFFSET($A$1,MATCH($G2,$A$2:$A$9,0),1,1,2))/2)

    Column G contains Student Names;
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-04-2017
    Location
    NJ
    MS-Off Ver
    Excel for Mac Version 15.31
    Posts
    75

    Re: compute an average if certain conditions are satisfied

    Hi John,

    Many many thanks for your help. I'm so glad I asked my question because judging the formula you provided, I would never have figured this out on my own. I'm in the process of looking up all the functions embedded in your formula (I'm an Excel newbie) and try to make sense of their logic, and I hope I will understand this formula enough in order to apply it.

    Thank you.

    Anita

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,004

    Re: compute an average if certain conditions are satisfied

    If you require any further help ..just ask!

    And ....

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  6. #6
    Registered User
    Join Date
    03-04-2017
    Location
    NJ
    MS-Off Ver
    Excel for Mac Version 15.31
    Posts
    75

    Re: compute an average if certain conditions are satisfied

    John,

    Sorry. I now have a basic understanding of each function (i.e., sumproduct, offset, and match) but still can't quite fully understand how all of those functions work together to produce the results. Would you kindly provide a translation of your formula into plain English?

    Thanks!

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,004

    Re: compute an average if certain conditions are satisfied

    =SUMPRODUCT(($E$2:$E$9)*($A$2:$A$9=$G2)*($D$2:$D$9=OFFSET($A$1,MATCH($G2,$A$2:$A$9,0),1,1,2))/2)

    ($E$2:$E$9) are the Grade scores

    which we need to match with the Student ......

    ($A$2:$A$9=$G2) (returns TRUE if matched)

    and we need to match the chosen subjects in columns B & C with those listed in column D ......

    ($D$2:$D$9=OFFSET($A$1,MATCH($G2,$A$2:$A$9,0),1,1,2))/2)

    the OFFSET function matches the name (G2) against the names in A which gives us the (first) row number for the student

    The first "1" in Offset positions us at Column B (offset 1 from A1), the second "1" is the height of one row and the 2 is the "width" (number of columns) we are including so this 2 for columns B & C (chosen grades): so we match data in column D against B & C for the selected row..

    So for Mary we will compare D2:D9 with B2:C2 and James with B6:C6

    Whenever we get a match (TRUE) this equates to value of 1 (FALSE = 0) so SUMPRODUCT multiplies and SUMs the grade scores by either 1 or 0 which results in SUM of the appropriate grade scores being returned.

    The "/2" then just averages the result.

    To see how this works, click on H2, then "Formulas"==>"Evaluate Formula"==>Evaluate.

    FYI: the formula could also be defined as (OFFSET changed) ...

    =SUMPRODUCT(($E$2:$E$9)*($A$2:$A$9=$G2)*($D$2:$D$9=OFFSET($B$1,MATCH($G2,$A$2:$A$9,0),0,1,2))/2)

    Hope this helps.

  8. #8
    Registered User
    Join Date
    03-04-2017
    Location
    NJ
    MS-Off Ver
    Excel for Mac Version 15.31
    Posts
    75

    Re: compute an average if certain conditions are satisfied

    Hi John,

    Your formula and your explanation has been incredibly helpful. I think I understand it and will now apply it to my situation.

    Thank you again for your help!

+ 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. Replies: 5
    Last Post: 08-18-2016, 09:13 AM
  2. Replies: 0
    Last Post: 08-02-2014, 03:22 PM
  3. Resetting running counter based on conditions being satisfied
    By Stdnt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-17-2014, 06:15 PM
  4. Conditional Formatting by VBA, Highlight color when If conditions satisfied
    By skhari in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-09-2012, 01:01 PM
  5. Replies: 2
    Last Post: 08-01-2011, 03:22 PM
  6. Linked Lookup IF 2 conditions are satisfied
    By reghu in forum Excel General
    Replies: 0
    Last Post: 09-01-2010, 07:13 AM
  7. Replies: 10
    Last Post: 08-28-2008, 06:45 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