Sum Distinct Records not duplicate Records

I currently have a formula as such

if {@grouporder_desc} = 'Non-Rent Other Account' then {glf_ldg_acc_trans.AMT1} else 0

I need a distinct SUM on glf_ldg_acc_trans.transnbr

Sorry not sure how to do that.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ido MilletProfessor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
If you are grouping on transnbr then you can simply create a Running Total that evaluates on group change.

Otherwise, you could create a global variable (delimited string or an array) that stores all distinct transnbr values encountered (your formula would check for each row if the transnbr is in already in the string or array variable.  If it is, ignore it -- if it isn't, add it to the string/array and add the value to be summed into a numeric variable.

If the number of distinct values is too large for a string or array variable in Crystal, there's one other option, but let's start with the simple options... :)
NewFocusConsultAuthor Commented:

Thank you for your response, unfortunately a Running Total won't work as the total will be placed in the page header not footer or group footer.

Not sure how to use variables, would love an example please?
Trying to use variables will have the same problem as using a running total.  The variables will be updated as the records are processed, so you won't have a total until the report gets to the last record in the group/report/whatever.

 Your only option in the report may be to use a subreport in the page header.  The subreport would read the same data and produce your total.  The first question would be, if your report is longer than a page, can you get the subreport to produce a total for just the data that's on the current page (assuming that you're looking for a page total)?

 If the report is using something like a stored procedure or view, where you control the query, then another option might be to generate the totals in the query (this may also depend on what's on each page of the report).


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Just curious.  What was your solution (since I posted a couple of possibilities) ?

NewFocusConsultAuthor Commented:
Sorry - Sub Report will work as the top group is the account.

OK.  Thanks.  FWIW, I imagine that a subreport was what Ido was alluding to in his last sentence, but I got to it before he did.  :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.