Calculate the first four cells based on condition

addy_89

New Member
Joined
Jul 9, 2014
Messages
21
ABCD
x16-03-20142
x16-03-20143
x16-03-20144
x16-03-20145
x16-03-20146
x17-03-20147
x17-03-20148
x17-03-20149
x17-03-201410
y17-03-20141

<colgroup><col><col><col span="2"></colgroup><tbody>
</tbody>


In the above example, i want to sum the first four cells where data in column a and column b is matching and after summing the first four values, i want excel to sum the rest of the values for the matching data in column in a and b which not necessary would be 4, but will be less. I have the written the array formula for this using count if and sumifs but that is giving me the sum of total values.

{=IF(COUNTIFS($A$2:$A3,A3,$B$2:$B3,B3)>1,"",SUMIFS(C:C,A:A,A3,B:B,B3))}

Is it possible? Please help, i'm stuck :(
 
I remembered an observation from an old thread that countif(s) and sumif(s) seem to be extremely inefficient when filled over a large range using an absolute start and relative end reference.
I wasn't aware of that. Will try to remember to test that out a bit more.


With this in mind, I cannibalized your formula and came up with

=IF(MOD(COUNTIFS(INDEX(A$1:A2,MAX(ROW(D2)-4,2)):A2,A2,INDEX(B$1:B2,MAX(ROW(D2)-4,2)):B2,B2),4)=1,SUMIFS(C2:C5,A2:A5,A2,B2:B5,B2),"")

250k rows took about 2-3 seconds, and no insufficient resource failures.
I still could not successfully apply that even with 200,000 rows.


Depends what sort of approach the OP wants to take and what the computer specs are but this may be another option for formulas.
You might let me know how fast it seems on your machine for the large data sample.
I've inserted 4 new blank rows (2:5) & hidden them.

Excel Workbook
ABCD
1ABCD
6x16/03/1477
7x17/03/14517
8x17/03/146
9x17/03/143
10x17/03/143
11x17/03/14715
12x17/03/141
13x17/03/147
14x18/03/1477
15x19/03/1411
16x20/03/1444
17x21/03/14829
18x21/03/148
19x21/03/144
20x21/03/149
21x21/03/14614
22x21/03/148
23x23/03/1411
24x24/03/14913
25x24/03/144
26y24/03/14513
27y24/03/147
28y24/03/141
29y26/03/14611
30y26/03/145
31
Sheet4
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You might let me know how fast it seems on your machine for the large data sample.

Of course Peter, I had to do this one with a vba timer, it was to fast for me to read the timestamps doing it manually.

Autofill start</SPAN>9:27:57.310</SPAN>
End</SPAN>9:27:59.030</SPAN>
Difference</SPAN>0:00:01.720</SPAN>
Recalc Start</SPAN>9:27:59.350</SPAN>
End</SPAN>9:28:00.030</SPAN>
Difference</SPAN>0:00:00.680</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL></COLGROUP>

I found an error in the change I made to your previous formula as well, so that is of no use. That said, the efficiency of your new formula would make that redundant anyway.

For reference I'm running I7 4500U with 8GB ram. Not sure how that compares for performance.
 
Upvote 0
Jason

Thanks for providing the timing info. That sounds pretty good to me. :)
 
Upvote 0
I'm soory, i was travelling for last 2 days and could not reply, that formula was working but i was putting it as array and hence the error. appologies
 
Upvote 0
That helps!!! thanks a lot jackson, but i've one more question, if I want to restrict the sum of c to a prticular value, if it crosses or equal to that value than it should return to the condition like:-

ab4000040000
ab3600036000
ab50006200
ab500Blank
ab400Blank
ab300Blank
cd4000040000
cd3600036000
cd60006000
cd50030900
cd400Blank
cd30000Blank

<tbody>
</tbody>


Please help ! :(
 
Upvote 0
So you're saying no sum should be greater than 40000?

Looking at the last 4 rows, could you explain why you have 6000, 30900, Blank, Blank and not 6900, Blank, Blank, 30000?

Are you able to use a vba / macro solution? To do this with a formula on 250k rows of data you're going to need the processing power of Tianhe-2!

Any thoughts Peter?

I'll keep on thinking, maybe another idea will come to mind.

Ja(ck)son:rolleyes:
 
Upvote 0
So you're saying no sum should be greater than 40000?

Looking at the last 4 rows, could you explain why you have 6000, 30900, Blank, Blank and not 6900, Blank, Blank, 30000?

Are you able to use a vba / macro solution? To do this with a formula on 250k rows of data you're going to need the processing power of Tianhe-2!

Any thoughts Peter?

I'll keep on thinking, maybe another idea will come to mind.

Ja(ck)son:rolleyes:

Jackson, First of all a very thanks to you for the help, I sounded mean before, but trust me that is not the case, I was really stuck and today when I saw you post again, I got the results!!! Thanks a lot :)

Yes you're correct the sum should not be greater than 40000.
You're again correct for the data, that was my mistake.
VBA can work, actually, I have broken my sheet in 4 sheets so it does take the formula but is very heptic to do. Its been 2 hours now since i'm stuck witrh this 40k thing. do you have any formula?

Please help :(
 
Upvote 0
Looking at the last 4 rows, could you explain why you have 6000, 30900, Blank, Blank and not 6900, Blank, Blank, 30000?

I will sort my table based on values so, this won't be the case. Thanks for observing. You guys are awesome :D
 
Upvote 0
Which formula are you using?

Go back to the top of the thread and check all of the replies, there has been a lot of activity in your absence, and a lot of very helpful ideas that you might have missed, ideas that I cannot take credit for.
 
Upvote 0
Which formula are you using?

Go back to the top of the thread and check all of the replies, there has been a lot of activity in your absence, and a lot of very helpful ideas that you might have missed, ideas that I cannot take credit for.

I saw all the discussion, I'm using the very first formula of yours.

=IF(OR(H2<>H3,I2<>I3,IFERROR(COUNTIF(X2:INDEX(X$1:X2,MATCH(1E+100,X$1:X2)),"")=3,0)),SUMIFS(W3:W6,H3:H6,H3,I3:I6,I3),"")

Index and match one, I was trying to put if condition in this formula and work, but that did not happen.
 
Upvote 0

Forum statistics

Threads
1,216,230
Messages
6,129,625
Members
449,521
Latest member
Anri

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