Count Rows Until A Certain Sum Value Is Reached based on addtl criteria

chefanator

New Member
Joined
May 31, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi - I am trying to sum the # of cells across a period of time until a certain threshold is reached from the value of those cells, but for multiple product codes in the same column. I was able to create the formula for sum until the threshold, but I am having trouble defining the second criteria for only focusing on the total units sold for a specific product. Can anyone assist. The formula I am using thus far is:

=MATCH(I$6,SUBTOTAL(9,OFFSET($C$7,,,ROW($C$7:$C$1000)-ROW($C$7))),1)

However, I need to add in an additional criteria to only focus on counting values in column C that match the product code in column H with the reference column A.

For example, in the attached screenshot, I want to find the "days to reach 50" for product 113 only.

Thanks in advance!

Screenshot 2022-05-30 083242.png


sales analysis.xlsx
ABCDEFGHIJKL
1
2OMIT(blank)
3NEWNEW
4threshold
5Sum of ordered_item_quantityproduct #50100250500
6product #dayTotal483
7481-Apr71133
8482-Apr101143
9483-Apr48115
10484-Apr53116
11485-Apr25117
12486-Apr29135
13487-Apr13137
14488-Apr12138
15489-Apr16141
164810-Apr18142
174811-Apr9143
184820-Apr6145
194826-Apr1147
20484-May1149
21485-May14150
22486-May10151
23487-May12156
24488-May14157
25489-May40
264810-May10
274811-May14
284812-May4
294813-May5
304814-May6
314815-May9
324816-May16
334817-May11
344818-May12
354819-May9
364820-May7
374821-May5
384822-May0
3911322-Jan13
4011323-Jan177
4111324-Jan40
4211325-Jan11
431136-Feb126
441137-Feb33
451138-Feb15
461139-Feb27
sales analysis
Cell Formulas
RangeFormula
H6:H24H6=UNIQUE($A$7:$A$963)
I6:I8I6=MATCH(I$5,SUBTOTAL(9,OFFSET($C$7,,,ROW($C$7:$C$1000)-ROW($C$7))),1)
Press CTRL+SHIFT+ENTER to enter array formulas.
Dynamic array formulas.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Count Rows Until A Certain Sum Value Is Reached based off addtl criteria
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
SUMtif with a Min

Book1
ABCDEFGHIJKL
1
2OMIT(blank)
3NEWNEW
4threshold
5Sum of ordered_item_quantityproduct #50100250500
6product #dayTotal4850100250446
7481-Apr711350100250442
8482-Apr1000000
9483-Apr48
10484-Apr53
11485-Apr25
12486-Apr29
13487-Apr13
14488-Apr12
15489-Apr16
164810-Apr18
174811-Apr9
184820-Apr6
194826-Apr1
20484-May1
21485-May14
22486-May10
23487-May12
24488-May14
25489-May40
264810-May10
274811-May14
284812-May4
294813-May5
304814-May6
314815-May9
324816-May16
334817-May11
344818-May12
354819-May9
364820-May7
374821-May5
384822-May0
3911322-Jan13
4011323-Jan177
4111324-Jan40
4211325-Jan11
431136-Feb126
441137-Feb33
451138-Feb15
461139-Feb27
Sheet2
Cell Formulas
RangeFormula
H6:H8H6=UNIQUE($A$7:$A$963)
I6:L8I6=MIN(SUMIF($A$7:$A$46,$H6,$C$7:$C$46),I$5)
Dynamic array formulas.
 
Upvote 0
Thanks, etaf, but I'm looking to sum the "# of cells" not the values in those cells. For example, for product 48, it took 3 days to reach the threshold of 50, and 4 days to reach threshold of 100, and 15 days to reach threshold of 250. My product list is long, and I want to be able to do this for each unique product #.
 
Upvote 0
I think this scenario requires a very complicated array formula - I'm using Excel 2010. Maybe someone with Excel 365 can come up with a simpler formula.
Would a macro be acceptable?

M.
 
Upvote 0
How about
++Fluff.xlsm
ABCDEFGHIJKL
1
2OMIT(blank)
3NEWNEW
4threshold
5Sum of ordered_item_quantityproduct #50100250500
6product #dayTotal483415#N/A
74801-Apr7113225#N/A
84802-Apr100
94803-Apr48
104804-Apr53
114805-Apr25
124806-Apr29
134807-Apr13
144808-Apr12
154809-Apr16
164810-Apr18
174811-Apr9
184820-Apr6
194826-Apr1
204804-May1
214805-May14
224806-May10
234807-May12
244808-May14
254809-May40
264810-May10
274811-May14
284812-May4
294813-May5
304814-May6
314815-May9
324816-May16
334817-May11
344818-May12
354819-May9
364820-May7
374821-May5
384822-May0
3911322-Jan13
4011323-Jan177
4111324-Jan40
4211325-Jan11
4311306-Feb126
4411307-Feb33
4511308-Feb15
4611309-Feb27
Data
Cell Formulas
RangeFormula
H6:H8H6=UNIQUE($A$7:$A$963)
I6:L7I6=LET(f,FILTER($C$7:$C$963,$A$7:$A$963=$H6),r,ROWS(f),XMATCH(I$5,MMULT(--(SEQUENCE(r)>=SEQUENCE(,r)),f),1))
Dynamic array formulas.
 
Upvote 0
Solution
I wouldn't know where to even begin to do that without some of the new functions.
Just out of curiosity...
Ugly array formula :eek: in I6 copied across and down

31052022 Testes.xlsm
ABCDEFGHIJKL
1
2OMIT(blank)
3NEWNEW
4threshold
5Sum of ordered_item_quantityproduct #50100250500
6product #dayTotal483415 
74801/04/20227113225 
84802/04/20221011413  
94803/04/202248
104804/04/202253
114805/04/202225
124806/04/202229
134807/04/202213
144808/04/202212
154809/04/202216
164810/04/202218
174811/04/20229
184820/04/20226
194826/04/20221
204804/05/20221
214805/05/202214
224806/05/202210
234807/05/202212
244808/05/202214
254809/05/202240
264810/05/202210
274811/05/202214
284812/05/20224
294813/05/20225
304814/05/20226
314815/05/20229
324816/05/202216
334817/05/202211
344818/05/202212
354819/05/20229
364820/05/20227
374821/05/20225
384822/05/20220
3911322/01/202213
4011323/01/2022177
4111324/01/202240
4211325/01/202211
4311306/02/2022126
4411307/02/202233
4511308/02/202215
4611309/02/202227
4711409/02/202276
4811410/02/202210
4911411/02/202220
Plan1
Cell Formulas
RangeFormula
I6:L8I6=IF(SUMIF($A$7:$A$49,$H6,$C$7:$C$49)>I$5,IFERROR(MATCH(I$5,SUBTOTAL(9,OFFSET(INDEX($C$7:$C$49,MATCH($H6,$A$7:$A$49,0)),,,ROW(INDEX($C$7:$C$49,MATCH($H6,$A$7:$A$49,0)):$C$49)-ROW(INDEX($C$7:$C$49,MATCH($H6,$A$7:$A$49,0)))+1)),1)+IF(ISNUMBER(MATCH(I$5,SUBTOTAL(9,OFFSET(INDEX($C$7:$C$49,MATCH($H6,$A$7:$A$49,0)),,,ROW(INDEX($C$7:$C$49,MATCH($H6,$A$7:$A$49,0)):$C$49)-ROW(INDEX($C$7:$C$49,MATCH($H6,$A$7:$A$49,0)))+1)),0)),0,1),1),"")
Press CTRL+SHIFT+ENTER to enter array formulas.


M.
 
Upvote 0
A macro

VBA Code:
Sub aTest()
    Dim rData As Range, rThreshold As Range, rProduct As Range
    Dim rD As Range, rT As Range, rP As Range
    Dim lCounter As Long, lTotal As Long, bFind As Boolean
    
    Set rData = Range("A7:C" & Cells(Rows.Count, "A").End(xlUp).Row)
    Set rThreshold = Range("I5:L5")
    Set rProduct = Range("H6:H" & Cells(Rows.Count, "H").End(xlUp).Row)
    
    For Each rT In rThreshold
        For Each rP In rProduct
            lTotal = 0
            lCounter = 0
            bFind = False
            For Each rD In rData.Columns(1).Cells
                If rP = rD Then
                    lCounter = lCounter + 1
                    lTotal = lTotal + rD.Offset(0, 2)
                    If lTotal >= rT Then
                        bFind = True
                        Exit For
                    End If
                End If
            Next rD
            If bFind Then Cells(rP.Row, rT.Column) = lCounter
        Next rP
    Next rT
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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