Partial Sum of a Column based on multiple conditions

DavidWT87

New Member
Joined
May 10, 2023
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hello. I am looking for a way to pull out some data in a more intelligent way than just manually analysing it.

I have flow rate values in Column B that over a period of time has two spikes (B4:B7), and (B11:B12), before steadily rising for a period of time, before falling back down again. These relate to the various stages shown in Column A (stage 20,40,60,70 & 80).

Let's say in cell D2 I want code/formula to interrogate Column A & B, and based on Column A having not reached stage 60, look at Column B, recognise when the first spike starts (B4 - ie goes above 0.05), recognises when the spike is over (B7 as subsequent cell is back below 0.05), and then sums each cell in that range (B4,B5,B6 & B7), and returns the answer in D2.

I then want it to continue analysing Column B based on Column A not yet having reached 60, and do the same for the 2nd spike and return the sum in cell D3. I am not interested in anything after Column A reaches 60.

Had a bit of a mess about with some SUMIFS but couldn't get anything to work, and not even sure if that's the best way to go about it.

Can anyone help. Thanks
 

Attachments

  • Data.JPG
    Data.JPG
    46.5 KB · Views: 12

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi David,

I don't think this is exactly what you're looking for, but it could be a stop-gap. I assumed that a spike cannot be through multiple stages, so I just did a sumifs based on >0.05 and the stage # - e.g. 20,40,60,70,80.

First Formula as so: =SUMIFS($B$1:$B$32,$A$1:$A$32,20,$B$1:$B$32,">0.05")

Book2
ABCDEF
1200.03616975.5449520<-Spikes
2200.03616939.5568140
3200.036169108.422560
4201.482928070
52019.94719080
62039.7256
72014.38923
8200.036169
9400.036169
10400.036169
11400.645014
124038.9118
13400.036169
14400.036169
15400.036169
16600.036169
17600.036169
18600.16276
196017.69266
206022.93716
216022.61164
226022.54533
236022.41874
24600.054253
25600.036169
26600.036169
27600.036169
28600.036169
29600.036169
30700.036169
31800.036169
32800.036169
Sheet1
Cell Formulas
RangeFormula
D1D1=SUMIFS($B$1:$B$32,$A$1:$A$32,20,$B$1:$B$32,">0.05")
D2D2=SUMIFS($B$1:$B$32,$A$1:$A$32,40,$B$1:$B$32,">0.05")
D3D3=SUMIFS($B$1:$B$32,$A$1:$A$32,60,$B$1:$B$32,">0.05")
D4D4=SUMIFS($B$1:$B$32,$A$1:$A$32,70,$B$1:$B$32,">0.05")
D5D5=SUMIFS($B$1:$B$32,$A$1:$A$32,80,$B$1:$B$32,">0.05")
 
Upvote 0
Here is another idea that relies on some helper columns to 1) determine if the Stage and Flow Rate Threshold criteria are met (column D) and to 2) split the Flow Rate vs. Time curve into distinct Zones representing regions where the curve is below the threshold and above the threshold (column E). Then the summary block (in shaded green) uses formulas to determine the sum of each spike. I do not know whether it is possible for a spike to stretch across a "Stage". If so, the approach offered by @dalvin647 will capture partial sums of the spike within each of those Stages...but this might not be a realistic concern (you'll need to assess that). In this example, the two spikes occur in Zones 2 and 4.
MrExcel_20230523.xlsx
ABCDEFGH
1Threshold >0.05
2Stage <60
3
4TimeStageFlow RateCriteria Met?ZoneZoneSum
51200.036169FALSE1275.54495
62200.036169FALSE1439.55681
73200.036169FALSE1  
84201.482928TRUE2  
952019.94719TRUE2  
1062039.7256TRUE2  
1172014.38923TRUE2
128200.036169FALSE3
139400.036169FALSE3
1410400.036169FALSE3
1511400.645014TRUE4
16124038.9118TRUE4
1713400.036169FALSE5
1814400.036169FALSE5
1915400.036169FALSE5
2016600.036169FALSE5
2117600.036169FALSE5
2218600.16276FALSE5
23196017.69266FALSE5
24206022.93716FALSE5
25216022.61164FALSE5
26226022.54533FALSE5
27236022.41874FALSE5
2824600.054253FALSE5
2925600.036169FALSE5
3026600.036169FALSE5
3127600.036169FALSE5
3228600.036169FALSE5
3329600.036169FALSE5
3430700.036169FALSE5
3531800.036169FALSE5
3632800.036169FALSE5
DavidWT87
Cell Formulas
RangeFormula
D5:D36D5=AND(B5<$D$2,C5>D$1)
E5:E36E5=IF(D5=D4,MAX(E$4:E4),MAX(E$4:E4)+1)
G5:G10G5=IFERROR(INDEX($E$5:$E$36,MATCH(1,(($D$5:$D$36)*($E$5:$E$36)>N(G4))*(COUNTIF(G$4:G4,$E$5:$E$36)=0),0)),"")
H5:H10H5=IFERROR(IF(AND(INDEX($D$5:$D$36,MATCH(G5,$E$5:$E$36,0)),G5<>""),SUMIF($E$5:$E$36,G5,$C$5:$C$36),""),"")
A5:A36A5=ROWS(A$5:A5)
 

Attachments

  • MrExcel20230523.png
    MrExcel20230523.png
    79.3 KB · Views: 6
Upvote 0
Here is another idea that relies on some helper columns to 1) determine if the Stage and Flow Rate Threshold criteria are met (column D) and to 2) split the Flow Rate vs. Time curve into distinct Zones representing regions where the curve is below the threshold and above the threshold (column E). Then the summary block (in shaded green) uses formulas to determine the sum of each spike. I do not know whether it is possible for a spike to stretch across a "Stage". If so, the approach offered by @dalvin647 will capture partial sums of the spike within each of those Stages...but this might not be a realistic concern (you'll need to assess that). In this example, the two spikes occur in Zones 2 and 4.
MrExcel_20230523.xlsx
ABCDEFGH
1Threshold >0.05
2Stage <60
3
4TimeStageFlow RateCriteria Met?ZoneZoneSum
51200.036169FALSE1275.54495
62200.036169FALSE1439.55681
73200.036169FALSE1  
84201.482928TRUE2  
952019.94719TRUE2  
1062039.7256TRUE2  
1172014.38923TRUE2
128200.036169FALSE3
139400.036169FALSE3
1410400.036169FALSE3
1511400.645014TRUE4
16124038.9118TRUE4
1713400.036169FALSE5
1814400.036169FALSE5
1915400.036169FALSE5
2016600.036169FALSE5
2117600.036169FALSE5
2218600.16276FALSE5
23196017.69266FALSE5
24206022.93716FALSE5
25216022.61164FALSE5
26226022.54533FALSE5
27236022.41874FALSE5
2824600.054253FALSE5
2925600.036169FALSE5
3026600.036169FALSE5
3127600.036169FALSE5
3228600.036169FALSE5
3329600.036169FALSE5
3430700.036169FALSE5
3531800.036169FALSE5
3632800.036169FALSE5
DavidWT87
Cell Formulas
RangeFormula
D5:D36D5=AND(B5<$D$2,C5>D$1)
E5:E36E5=IF(D5=D4,MAX(E$4:E4),MAX(E$4:E4)+1)
G5:G10G5=IFERROR(INDEX($E$5:$E$36,MATCH(1,(($D$5:$D$36)*($E$5:$E$36)>N(G4))*(COUNTIF(G$4:G4,$E$5:$E$36)=0),0)),"")
H5:H10H5=IFERROR(IF(AND(INDEX($D$5:$D$36,MATCH(G5,$E$5:$E$36,0)),G5<>""),SUMIF($E$5:$E$36,G5,$C$5:$C$36),""),"")
A5:A36A5=ROWS(A$5:A5)
 
Upvote 0
Hello. Thanks, this looks like it's going to do exactly what I want it to do.

The only issue I'm having is the nothing is being returned in the zone/sum cells (the iferror formulas).

Is there anything you can see as to why it's not coming up? (The data is expanded more over what I posted initially - I took out a few rows here and there to make it a manageable set of data to talk around.

(I've also added in a couple of formula for my mass flow threshold, and bringing in the stage/flow rate data from another tab so that hopefully I can superimpose this calculation sheet into many different sets of data)

Cell Formulas
RangeFormula
D1D1=C21+0.0001
B4:B57B4='RAW DATA'!AX1
C4:C57C4='RAW DATA'!BB1
A5:A57A5=ROWS(A$5:A5)
D5:D57D5=AND(B5<$D$2,C5>D$1)
E5:E57E5=IF(D5=D4,MAX(E$4:E4),MAX(E$4:E4)+1)
G5:G9G5=IFERROR(INDEX($E$5:$E$57,MATCH(1,(($D$5:$D$57)*($E$5:$E$57)>N(G4))*(COUNTIF(G$4:G4,$E$5:$E$57)=0),0)),"")
H5:H9H5=IFERROR(IF(AND(INDEX($D$5:$D$57,MATCH(G5,$E$5:$E$57,0)),G5<>""),SUMIF($E$5:$E$57,G5,$C$5:$C$57),""),"")
 
Upvote 0
I have an idea...since you are using Excel 2016, array formulas are not natively handled unless you specify the formulas as such. Excel 365, which I am using, automatically recognizes the array formulas so the following steps are not necessary for the initial setup. I believe you may need to do this: Select cell G5, go to the formula bar at top and click F2 to enter into edit mode, then hit Ctrl-Shift-Enter to re-confirm the formula as an array formula. You should see curly brackets surround the formula in the formula bar. Then drag that formula down some appropriate number of cells (G5:G9 maybe?)...by clicking, holding, and dragging the small green rectangle that appears in the lower right corner of the cell when you select it. That should populate the G cells with the Zone numbers associated with the spikes. Do the same for the H column formula. And please let me know if that resolves the issue.
 
Upvote 0
I have an idea...since you are using Excel 2016, array formulas are not natively handled unless you specify the formulas as such. Excel 365, which I am using, automatically recognizes the array formulas so the following steps are not necessary for the initial setup. I believe you may need to do this: Select cell G5, go to the formula bar at top and click F2 to enter into edit mode, then hit Ctrl-Shift-Enter to re-confirm the formula as an array formula. You should see curly brackets surround the formula in the formula bar. Then drag that formula down some appropriate number of cells (G5:G9 maybe?)...by clicking, holding, and dragging the small green rectangle that appears in the lower right corner of the cell when you select it. That should populate the G cells with the Zone numbers associated with the spikes. Do the same for the H column formula. And please let me know if that resolves the issue.
Yes! That's done the job. Nice one (y)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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