+ Reply to Thread
Results 1 to 10 of 10

Average last n values based on criteria from 2 columns

  1. #1
    Registered User
    Join Date
    10-26-2021
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Average last n values based on criteria from 2 columns

    I have 2 columns, col 1 has inputs (0.6, 0.5, 0.7, etc), and col 2 has binary results (0 or 1)... I want to average the "last 10" values from the results column, but only average if the input column is greater than 0.6...

    The formula below works great, except it averages the last 10 values regardless if they are >0.60 or not, and I can't figure out a way to only average the last 10 if they meet the >0.6 criteria.

    =ArrayFormula(iferror(average(query(if(len(A2:A),{ROW(A2:A),B2:B},),"Select Col2 where Col1>0.60 and Col2>-1 order by Col1 Desc limit 10"))))


    (answers that work in Sheets as well would be fantastic)
    Thanks in advance!

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,725

    Re: Average last n values based on criteria from 2 columns

    Hello cojohnst5412. Welcome to the forum.

    Perhaps you overlooked the 'gold' banner at the top of the page HOW TO ATTACH YOUR SAMPLE WORKBOOK:

    In the meantime, in general terms, see if this helps.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  3. #3
    Registered User
    Join Date
    10-26-2021
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Re: Average last n values based on criteria from 2 columns

    I think I just uploaded a sample file, my apologies
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Average last n values based on criteria from 2 columns

    Dave has the answer, I think, in his #2 post - give or take a column number tweak in the second half of the formula:

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

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,725

    Re: Average last n values based on criteria from 2 columns

    Now that I've seen your upload I also see that I may have interpreted wrong. Try this instead. In Excel 2013 you will have to array enter this:

    If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,725

    Re: Average last n values based on criteria from 2 columns

    BTW:
    My first formula returns 0.611. My last one returns 0.4 which is what you indicate in your upload is expected.

  7. #7
    Registered User
    Join Date
    10-26-2021
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Re: Average last n values based on criteria from 2 columns

    Thank you so much for the help! Will work on testing this out soon...

    I know it's an Excel forum, but by any chance is there a way this is portable to Google Sheets as well? I haven't tried an array formula Sheets before.

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,725

    Re: Average last n values based on criteria from 2 columns

    I don't know. I am not familiar with Google Sheets.

    There is a sub-forum here for other platforms Forum: For Other Platforms(Mac, Google Docs, Mobile OS etc)

    Would you like me to move your thread there?

  9. #9
    Registered User
    Join Date
    10-26-2021
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Re: Average last n values based on criteria from 2 columns

    Seems to work on both, thanks so much for the help! Really appreciate it!

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,725

    Re: Average last n values based on criteria from 2 columns

    You are welcome.

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

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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: 2
    Last Post: 08-16-2020, 09:46 PM
  2. Average LAST 6 Values in a Column, based on criteria
    By StormFusion in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-05-2019, 07:55 PM
  3. Sheets - How to average the top 25% of values based on criteria
    By BuyMeVinyl in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 7
    Last Post: 07-20-2019, 08:22 AM
  4. [SOLVED] Average amount of latest 4 values based on criteria
    By goodguyrulz in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 11-12-2018, 09:08 AM
  5. [SOLVED] Average Based on Multiple Criteria in Same and Different Columns
    By KoolKatelyn in forum Excel Formulas & Functions
    Replies: 28
    Last Post: 02-20-2018, 02:15 PM
  6. Getting an average across columns based on criteria.
    By anthony1312002 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2017, 03:06 PM
  7. [SOLVED] Average Based on Criteria in Multiple Columns
    By sinspawn56 in forum Excel General
    Replies: 2
    Last Post: 07-31-2012, 01:27 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