+ Reply to Thread
Results 1 to 7 of 7

Complex IF statement with average calculation.

  1. #1
    Registered User
    Join Date
    02-15-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    5

    Complex IF statement with average calculation.

    Sorry the title wasn't very descriptive, wasn't sure how to word this.

    I have a spreadsheet with three columns: 1st Observation, 2nd Observation, Average.

    In the observation columns, there will either be a number 1-5, or the letter 'N'.

    For the average column:

    If both columns contain "N", then the average column should be "N" - simple enough.
    If neither column contains "N", then the average of the two numbers/observations should be calculated - also simple.
    If only one column contains the letter "N', then the number from the column which isn't "N" should be returned.


    So for example:

    1st: 5, 2nd: 6, Average: 5.5
    1st: N, 2nd: N, Average: N
    1st: N, 2nd: 4, Average: 4
    1st: 3, 2nd: N, Average, 3


    How would I go about doing this?

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Complex IF statement with average calculation.

    =if(and(a1="n",b1="n"),"n",if(a1="n",b1,if(b1="n",a1,average(a1,b1))))
    Ben Van Johnson

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

    Re: Complex IF statement with average calculation.

    Try this in C2:

    IF(A2&B2="NN","N",IF(COUNTIF(A2:B2,"N")=1,SUM(A2:B2),(A2+B2)/2))

    then copy down.

    Hope this helps.

    Pete

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Complex IF statement with average calculation.

    =if(countif(F1:G1,"N,")>=1,"N",average(F1:G1)) and drag down.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  5. #5
    Registered User
    Join Date
    02-15-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    5

    Re: Complex IF statement with average calculation.

    Quote Originally Posted by protonLeah View Post
    =if(and(a1="n",b1="n"),"n",if(a1="n",b1,if(b1="n",a1,average(a1,b1))))
    Thank you! This worked with a little tweak:

    =IF(AND(J6="N",K6="N"),"N",IF(J6="N",K6,IF(K6="N",J6,SUM(J6+K6)/2)))

    Not sure why the average didn't work as it was.

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

    Re: Complex IF statement with average calculation.

    Another variation, adjusted for your real cells:

    =IF(J6&K6="NN","N",SUM(J6:K6)/(2-(COUNTIF(J6:K6,"N")=1)))

    Not as many IFs now.

    Hope this helps.

    Pete

  7. #7
    Registered User
    Join Date
    02-15-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    5

    Re: Complex IF statement with average calculation.

    Quote Originally Posted by Pete_UK View Post
    Another variation, adjusted for your real cells:

    =IF(J6&K6="NN","N",SUM(J6:K6)/(2-(COUNTIF(J6:K6,"N")=1)))

    Not as many IFs now.

    Hope this helps.

    Pete
    This didn't work for me, I'm afraid.

+ 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] Conditional statement calculation based on result of previous calculation.(Need some help)
    By takeprofit in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-01-2012, 01:45 AM
  2. Excel 2007 : Complex calculation help
    By Betadog in forum Excel General
    Replies: 5
    Last Post: 04-20-2011, 05:06 PM
  3. Complex CSA Calculation
    By NatashaBatsford in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-28-2009, 10:42 AM
  4. Complex If Calculation Help
    By Marcus Gee in forum Excel General
    Replies: 3
    Last Post: 02-26-2008, 07:00 AM
  5. complex calculation
    By wislndixie in forum Excel General
    Replies: 1
    Last Post: 12-06-2007, 03:13 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