Summary fields produce different totals depending on the context in which you use them. In a calculation, the summary field returns a value based on the entire found set--not the subsets produced when you sort records in a sort order that includes the "when sorted by" field specified for a sub summary layout part.
To get those sub totals to use in a calculation, use the GetSummary ( SummaryField ; BreakField ) function. For "break field", select the same field that you have selected as the "when sorted by" field in your sub summary layout part.
Thanks. But what should I do when I sort by several fields at the same time?
It doesn't matter. What matters is that your break field match the "sort by" field setting in the sub summary part that shows the same sub total you want to use in your calculation. (Note that you don't specify multiple fields for the same sub summary part even though you may sort on multiple fields to set up the report.)