Subtotal doesn't work properly

Siepe1990

New Member
Joined
Jan 7, 2014
Messages
5
I've used subtotal a lot and never has it failed me. However, now I am lost. Here's my data-set (simplified for example):

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]With Formula[/TD]
[TD]Flat Data[/TD]
[/TR]
[TR]
[TD]Value[/TD]
[TD]10.000[/TD]
[TD]10.000[/TD]
[/TR]
[TR]
[TD]Value[/TD]
[TD]10.000[/TD]
[TD]10.000
[/TD]
[/TR]
[TR]
[TD]Result[/TD]
[TD][/TD]
[TD]20.000
[/TD]
[/TR]
[TR]
[TD]Value[/TD]
[TD]10.000[/TD]
[TD]10.000[/TD]
[/TR]
[TR]
[TD]Value[/TD]
[TD]10.000[/TD]
[TD]10.000[/TD]
[/TR]
[TR]
[TD]Value[/TD]
[TD]10.000[/TD]
[TD]10.000[/TD]
[/TR]
[TR]
[TD]Result[/TD]
[TD][/TD]
[TD]50.000[/TD]
[/TR]
</tbody>[/TABLE]

The formula I use is the following (cell B2):

=IF($A2="Value";5*2000;SUBTOTAL(9;$B$1:B1))

It gives 10.000, like it should. Next, cell B3:

=IF($A2="Value";5*2000;SUBTOTAL(9;$B$1:B2))

Nice, now B4 should give me the total of the 2 rows above. However, it doesn't...

Now, if I put the value (10.000) as a hard copy, the formula works all of a sudden...

Anybody where who can help me out?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
SUBTOTAL appears to be working right to me. It only ignores the other cells with a SUBTOTAL function.
With the $B$1 being fixed, you'll always catch the equivalent of total through..
So its always ignoring your formula because your IF... formula includes a SUBTOTAL function.
 
Last edited:
Upvote 0
Hi

Subtotal is working OK. Like SpillerBD said Subtotal() ignores other subtotal() results, that's why you are getting the 50.000 you want in B8 and not 70.000 that would be the sum of all the values above.

My question is

...Next, cell B3:

=IF($A2="Value";5*2000;SUBTOTAL(9;$B$1:B2))
...

why would you use Subtotal() in B3?
 
Upvote 0
Thanks for the reactions both of you. I think my explanation is not quite clear enough - struggling with explaining what I want - so I've uploaded the sample file:

https://gofile.io/?c=V380wa

As you can see in column B, the subtotal() doesn't add up to 20.000 (the first Result-row) or to 50.000 (the second Result-row).

Reason why I want to do it like this is that I have a large dataset (weekly changing as well) where 'Result' lines are mixed with 'Value' lines.
If it is a 'Value' line I want it to perform a calculation (more difficult than in the example I shared) ; if it is a 'Result' line, I want it the calculate the sum of the lines above but ignoring the other 'Result' lines. I figured subtotal() should do the trick easily, but somehow it doesn't work...
 
Upvote 0
this is how the subtotal() works, it will ignore other cells that with subtotal() to avoid double counting.
as the cells in Column B are all with subtotal(), that wouldn't work as it stand

try this


Book1
AB
1With Subtotal
2
3Value10,000
4Value10,000
5Result20,000
6Value10,000
7Value10,000
8Value10,000
9Result50,000
Sheet1
Cell Formulas
RangeFormula
B3=IF(A3="Value",5*2000,SUMPRODUCT(--($A2:A$3="Value"),$B2:B$3))
 
Last edited:
Upvote 0
Hi

Try in B2:

=IF($A2="Value",5*2000,SUMIF($A$1:A1,"Value",$B$1:B1)-SUMIF($A$1:A1,"Result",$B$1:B1))

or, same thing a bit shorter

=IF($A2="Value",5*2000,SUM(SUMIF($A$1:A1,{"Value","Result"},$B$1:B1)*{1,-1}))

Copy down
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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