Solved

conditional running total in crystal reports

Posted on 2010-11-22
12
915 Views
Last Modified: 2013-11-15
I'm using Crystal reports 2008 and sql server 2005. I've a report with data as following:
Dealer Name     Account #               Inspection Type
123                   4000857733            DSI
123                   4000857733            No Inspection
123                   4000857733            No Inspection
I've a group on Dealer Name.
Whenever I've a situation like above, where there are multiple inspection types, I always want to do a distinct count of account number based on the inspection type but if there's DSI OR there's both DSI and No Inspection for the same account number, then the running total for the no inspection type condition should be 0 and it should be 1 for DSI. Like in above case, the total for DSI should be 1 and total for No Inspection should be 0.
Please help.

Thanks.
Subash
0
Comment
Question by:subash011
  • 4
  • 2
  • 2
  • +2
12 Comments
 
LVL 7

Expert Comment

by:mkobrin
ID: 34194038
Is the account# unique to the dealer name, and/or can a dealer name have multiple account numbers?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34194164
you can group by inspection type then do a count for each type.

What if there is only No Inspection?

mlmcc
0
 

Author Comment

by:subash011
ID: 34196749
mkobrin: Yes a dealer can have multiple account numbers. For eg.,
Dealer Name     Account #               Inspection Type
123                   4000857733            DSI
123                   4000857733            No Inspection
123                   4000857733            No Inspection
123                   4000857734            DSI
123                   4000857735            No Inspection
mlmcc: I did a group on inspection type and did a count. However, it works for other condition except if there's only No Inspection, like in above eg, I don't get a count of 1 for account number 4000857735. The business requirement is if there's more than 1 inspection type for the same account no, DSI and No Inspection, i should only count for DSI. If there's only No Inspection I should count it as No Inspection. In above example, my total for DSI should be 2 (1 for account # 4000857733 and 1 for account # 4000857734) and total for No Inspection should be 1 (for account # 4000857735). Instead I get total for DSI = 2 and total for No Inspection = 3. Please help. Thanks.

0
 
LVL 11

Expert Comment

by:tickett
ID: 34221430
Create a formula account_no with the code:

If {inspection_type} = "no inspection" then
 1
else
 {account_number}

Then distinct count that.
L
0
 

Author Comment

by:subash011
ID: 34223887
That formula won't work. I think what you meant is:
If {inspection_type} = "no inspection" then
 1
else
0
Then distinct count that. If I do a distinct count on above formula, I get a count of 2. One for DSI and other for No Inspection.
Please advise.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Accepted Solution

by:
James0628 earned 400 total points
ID: 34227643
I think that you're going to have to use formulas and variables for this.

 You'll need to add a group on the Account #, if you don't already have one.

 Create a formula like the following and put it in the report header to initialize the variables:

NumberVar no_insp_count;
NumberVar DSI_count;
no_insp_count := 0;
DSI_count := 0;
""

 The "" at the end is so that the formula doesn't produce any output on the report.

 Create 2 formulas like the following (let's call them @no_insp and @DSI):

// no_insp
if {Inspection Type} = "No Inspection" then
  1


// DSI
if {Inspection Type} = "DSI" then
  1


 Create a formula like the following and put it in the Account # group footer:

NumberVar no_insp_count;
NumberVar DSI_count;
if Sum ({@DSI), {Account #}) = 0 then
  no_insp_count := no_insp_count + 1
else
  DSI_count := DSI_count + 1;
""

 The idea is that if there are no DSI records for an account, increment the "No Inspection" count by 1, otherwise increment the DSI count.

 Then use formulas like the following to output the counts:

NumberVar no_insp_count


NumberVar DSI_count



 I don't think you've said whether you're looking for counts for the whole report or each dealer or something else.  If it's for the whole report, you can use formulas like the last 2 above in the report footer.  If it's for the dealer, you can use the formulas in the dealer group footer, but you'll also need to put the first formula above (to initialize the variables) in the dealer group header (in addition to the report header), to reset the counts for each new dealer.  If you need both, you'll need to add 2 more variables, one set for the dealer counts and one for the grand total counts.

 James
0
 
LVL 11

Expert Comment

by:tickett
ID: 34228975
Can you attach the report with data? (or even without data should help).

My formula should work if you've got the grouping setup how i'm imagining.

L
0
 
LVL 34

Expert Comment

by:James0628
ID: 34229561
tickett,

 I don't think a formula like that is going to work, for at least a couple of reasons.  First of all, subash011 wants a separate count for DSI and "No Inspection", and obviously there's no way to get both of those by doing a distinct count on one formula.  And that formula doesn't take into account the fact that the "No Inspection" count should only be incremented when an account has no DSI records.

 James
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 100 total points
ID: 34232979
Here is a report that provides the data you want.  If you need an overall summary you will need to use arrays to contain the data.

mlmcc
Q-26632980.rpt
Q-26632980.mdb
0
 

Author Comment

by:subash011
ID: 34284128
Thanks everyone! You guys are great.
mlmcc: Thank you so much for uploading the report with database and looking into for me. I looked at the report and its partially right. It's working for DSI but not for No Inspection. For instance, the count for account no. 4000857735 for no inspection should be 1 but it's 0 in the report. But that was a huge help for me as I created my own version of formula based on your logic. Thanks again.
0
 

Author Closing Comment

by:subash011
ID: 34284154
The solutions provided were great although not exact but gave me few different ideas based on which I created formulas to solve the problem. However without your expertise that wouldn't be possible.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now