How to sum values in a column that are greater than 1,500 but only sum the occurrences after the first 12?

spinitback

New Member
Joined
Aug 10, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all. I'm using Excel for M365

I have a column of numbers
1597089807514.png



In this column I have 17 occurrences of a number greater than equal to 1500.
For the first 12 occurrences of a value greater than equal to 1500, I don't want to do anything.
For all other occurrences in that column (in the above example, 5 occurrences) with a value greater than equal to 1,500, I want to automatically calculate the sum of those occurrences.
ie for this column: 1500+3000+1500+3000+1500 = 10500

I'm hoping the forum can help, thanks!
-Spin
 

Attachments

  • 1597089766996.png
    1597089766996.png
    5.4 KB · Views: 6

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Forgot to mention - I need help with a formula to do this as I have a large table spanning several years.

Thanks
S
 
Upvote 0
don't you think Power Query would be better especially with large data?
RawTable1
150010500
1500
500
1500
3000
500
1500
3000
500
1500
1500
500
3000
1500
500
1500
3000
500
1500
3000
1500
500
3000
1500

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Raw", Int64.Type}}),
    Filter = Table.SelectRows(Type, each [Raw] >= 1500),
    Top12 = Table.Skip(Filter,12),
    Sum = List.Sum(Top12[Raw])
in
    Sum
 
Upvote 0
thanks sandy, I appreciate the help. Is there a way to turn your power query code into an excel formula?
 
Upvote 0
thanks sandy, I appreciate the help. Is there a way to turn your power query code into an excel formula?
maybe but I don't know
but it should be easy
- filter >=1500
- sumif (maybe)
- sum the rest

but i am sure soon any formula master will give a solution :)
 
Upvote 0
Not sure how you would do this without using a helper column. So here is a way to do it either using a helper column or using the custom function included below.

New Document (2).xlsx
ABCD
11500110500Formula
21500210500VBA Custom Function
35002
415003
530004
65004
715005
830006
95006
1015007
1115008
125008
1330009
14150010
1550010
16150011
17300012
1850012
19150013
20300014
21150015
2250015
23300016
24150017
Sheet9
Cell Formulas
RangeFormula
C1C1=SUMIFS($A$1:$A$24,$A$1:$A$24,">=1500",$B$1:$B$24,">12")
C2C2=xSum(A1:A24,1500,12)
B1:B24B1=COUNTIF($A$1:A1,">=1500")


VBA Code:
Function xSum(r As Range, Limit As Integer, IDX As Integer) As Integer
Dim AR() As Variant: AR = r.Value2
Dim CNT As Integer: CNT = 0

For Each a In AR
    If a >= Limit Then
        CNT = CNT + 1
        If CNT > IDX Then xSum = xSum + a
    End If
Next a
End Function
 
Upvote 0
Not sure how you would do this without using a helper column. So here is a way to do it either using a helper column or using the custom function included below.

New Document (2).xlsx
ABCD
11500110500Formula
21500210500VBA Custom Function
35002
415003
530004
65004
715005
830006
95006
1015007
1115008
125008
1330009
14150010
1550010
16150011
17300012
1850012
19150013
20300014
21150015
2250015
23300016
24150017
Sheet9
Cell Formulas
RangeFormula
C1C1=SUMIFS($A$1:$A$24,$A$1:$A$24,">=1500",$B$1:$B$24,">12")
C2C2=xSum(A1:A24,1500,12)
B1:B24B1=COUNTIF($A$1:A1,">=1500")


VBA Code:
Function xSum(r As Range, Limit As Integer, IDX As Integer) As Integer
Dim AR() As Variant: AR = r.Value2
Dim CNT As Integer: CNT = 0

For Each a In AR
    If a >= Limit Then
        CNT = CNT + 1
        If CNT > IDX Then xSum = xSum + a
    End If
Next a
End Function

Hey, thanks for the help! Is there a way to do the Excel formula without the need for the "B" column, ie just based on the A column? I have a column for each month for 4 years.
 
Upvote 0
Try This without countif helper

=IFERROR(SUM(INDEX($A$2:$A$25,AGGREGATE(15,6,1/(1/((A2:A25>=1500)*(ROW($A$2:$A$25)-ROW($A$2)+1))),ROW(INDIRECT("A13:A"&COUNTIF(A2:A25,">="&1500)))))),0)
 
Upvote 0
Nice @CA_Punit, looks better than the nightmare formula I came up with.

New Document (2).xlsx
ABC
1150010500
21500
3500
41500
53000
6500
71500
83000
9500
101500
111500
12500
133000
141500
15500
161500
173000
18500
191500
203000
211500
22500
233000
241500
Sheet9
Cell Formulas
RangeFormula
C1C1=SUMIF(OFFSET(A1:A24,SMALL(IF(A1:A24>=1500,ROW(A1:A24)-ROW(A1)+1),13)-1,0,ROWS(A1:A24)-SMALL(IF(A1:A24>=1500,ROW(A1:A24)-ROW(A1)+1),13)+1),">=1500",OFFSET(A1:A24,SMALL(IF(A1:A24>=1500,ROW(A1:A24)-ROW(A1)+1),13)-1,0,ROWS(A1:A24)-SMALL(IF(A1:A24>=1500,ROW(A1:A24)-ROW(A1)+1),13)+1))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Try This without countif helper

=IFERROR(SUM(INDEX($A$2:$A$25,AGGREGATE(15,6,1/(1/((A2:A25>=1500)*(ROW($A$2:$A$25)-ROW($A$2)+1))),ROW(INDIRECT("A13:A"&COUNTIF(A2:A25,">="&1500)))))),0)

Thanks for the help. What is the significance of the "A13:A" reference? Each column will be different, ie with difference values. Is this A13 only for this example?.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top