• Sum of N Largest Numbers in a List

    Author
    Topic
    #497825

    I would like to sum the largest 15 numbers in a list selected by using LARGE and criteria for a date range.

    I have attached a wks with sample data and some very simple formulas which work. I created a LARGE formula and manually selected a range to coincide with the date range I need to sum. Is there a way to incorporate the LARGE formula within the SUMIFS formula so that I don’t need to manually select the date ranges to work within? My actual data table is over 100k rows.

    Viewing 5 reply threads
    Author
    Replies
    • #1481018

      Arcturus,

      How about this:

      C3: [noparse]=SUMIFS($B$11:$B$70,$A$11:$A$70,”>”&DATE(2012,12,31),$A$11:$A$70,”=”&$B3)[/noparse]
      C4: [noparse]=SUMIFS($B$11:$B$70,$A$11:$A$70,”>”&DATE(2013,12,31),$A$11:$A$70,”=”&$B4)[/noparse]

      38763-Articus

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1481252

      Hey Y’all,

      A funny thing. Maud pointed out that I had a typo in the post above (it’s fixed now) where I had Date(2012,21,31) vs Date(2012,12,31)!

      The interesting thing is that those formulas were copied out of a worksheet (as depicted) and they returned the correct values! I tested by changing the 21 to 12 and it still calculated the same answer! :confused:

      Well this worked because [noparse]=Date(2012,21,31)[/noparse] will translate to 10/1/2013! the range being tested comes out to 10/1/2013 – 1/1/2014 and all the entries were dated 11/30/2013 so they fell within the range calculating the expected result.

      The reason I bothered to post about this is to reinforce the need to do EDGE testing, e.g. testing using values just outside & inside of the limits of the parameters to make sure the formulas are correct. This type of testing would have caught the error.

      Thanks again to Maud for catching the error and pointing it out to me in a PM. HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1481255

      Is there a way to incorporate the LARGE formula within the SUMIFS formula

      Your more than welcome RG.

      A tweak to RG’s formula that sums the values by year but finds the largest 15 values within the formula without having to reference a cell for the values (B3 and B4). The formulas also work if the dates are not in order.

      C3: [noparse]=SUMIFS($B$11:$B$70,$A$11:$A$70,”>”&DATE(2012,12,31),$A$11:$A$70,”=”&LARGE(IF(YEAR(A11:A70)=2013,B11:B70,””),15))[/noparse]

      C4: [noparse]=SUMIFS($B$11:$B$70,$A$11:$A$70,”>”&DATE(2013,12,31),$A$11:$A$70,”=”&LARGE(IF(YEAR(A11:A70)=2014,B11:B70,””),15))[/noparse]

      NOTE: These are array formulas and { } must be added using Ctrl-Shift-Enter

      38777-Array1

      HTH,
      Maud

    • #1481257

      Is it just my computer that in my post #4 and RG’s Post #2, a space was inserted between the 3 and the 1:

      DATE(2012,12,3 1)

    • #1481258

      Maud,

      I try to remember to always include formulas in [noparse][noparse] [/noparse][/noparse] tags to prevent that sort of thing but it doesn’t always work!. HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1481318

      Excel alerted me to the extra space in the formula so I knew right away how to fix it. Thanks to you Maudibe for the all-in-one solution.

      RG Thanks for explaing about the testing around the edges. I already try that a little but never knew a name for it.

      Now I can replace this formula in B3: =LARGE(B11:B40,15) with this B3: {=LARGE(IF(YEAR(A11:A70)=2013,B11:B70,””),15)}
      which allows me to select the entire range to evaluate without first having to determine the “2013” range manually.

      You guys are great! Thanks again.

    Viewing 5 reply threads
    Reply To: Sum of N Largest Numbers in a List

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: