Conditional group SUM in Crystal Reports
You probably figured this out a year ago, but just in case, try this:
Change your CanadianCommissionSum formula to
SUM({@CanadianCommissionFormula},{SalesRep})
Put this formula in your SalesRep's Group Footer section.
This should now display properly.
Nathan Koop
I'm currently a Sr. Dev/tech lead at Bold Commerce. I work with PHP, Laravel, Eloquent, React, Redux, GoLang, MySQL and more.
Updated on August 22, 2020Comments
-
Nathan Koop over 3 years
I've been doing some accounting reports and have been summing up my different currencies using a formula
IE
CanadianCommissionFormula
if {myData;1.CurrencyType} = "CDN" then {myData;1.Commission} else 0
CanadianCommissionSumSUM({@CanadianCommissionFormula})
Then I'd just display the CanadianCommissionSum at the bottom of the report and things were great.
I've just come across the requirement to do this, but grouped by Sales Rep. I tried using my previous formula, but this sums for the whole report. Is there an easy way to sum like this, based on which group it's in?
-
Nathan Koop over 14 yearsthat, unfortunately gives me the sum for all the sales reps
-
Nathan Koop over 14 yearshow do I get it to reset on the change of the group?
-
OMG Ponies over 14 yearsThen you aren't grouping by sales rep, or the sales rep info isn't what you think it is.
-
OMG Ponies over 14 yearsYou can setup running totals through functions, or use the Running Total feature in the same widget where you list the functions/etc.
-
Nathan Koop over 14 yearsWhen I look at the Group Expert I see the field SalesRep in the "Group By" portion. Then, using the formulas I've got listed above, I add the formula from your answer in the GroupFooterSection1 area, it then displays the total SUM for all Canadian Commissions, not the individual rep.
-
OMG Ponies over 14 yearsSo on the report, you see a group header above the details section, and the corresponding group footer underneath - the formula is in the group footer section...
-
OMG Ponies over 14 yearsIs any other data relating to sales rep coming out properly in the grouping?
-
Nathan Koop over 14 yearsYep, the group header is above the details section and there is a group footer, everything else displays great.
-
Nathan Koop over 14 yearsI don't want to waste too much of your time, I thought of another way to resolve this issue. I can add two more columns in my SQL query and a couple of CASE statements. IE CASE currency WHEN "CDN" THEN commissionAmount ELSE 0 END AS CdnCommission. Then I can sum up this in the group.
-
Arushi Rajput over 14 yearsWhen you set up the new running total field you will see a "Reset" section which is where you set it to "On change of group" and then select your group. This will reset the field back to zero every time that group changes.
-
OMG Ponies over 14 yearsBy all means, do as much as you can in the SQL. See if your db supports WITH ROLLUP on the GROUP BY clause - the output might help even more.
-
Hammad Khan over 12 yearsthis helped me a little but I have a question here if you can answer stackoverflow.com/questions/7987228/crystal-report-group