Solved

Crystal Formula

Posted on 2014-01-07
6
459 Views
Last Modified: 2014-01-14
Hi,

I am trying to make the following formula work. I guess, I am looking for a sub query. I have tried the following..

local numbervar CntInformedRes;
CntInformedRes :=
if date({Archive_tblEvents.TableDate}) = today
and {Archive_tblEvents.SubStatusGroup} = "Accepted - Informed Reserve"
then 1 else 0;

local numbervar SumInformedRes;
SumInformedRes :=
if date({Archive_tblEvents.TableDate}) = today
and {Archive_tblEvents.SubStatusGroup} = "Accepted - Informed Reserve"
then {Archive_tblEvents.OutstandingReserves} else 0;

Sum(SumInformedRes) / Sum(CntInformedRes)



This doesn't work, it wants a field. It doesn't accept the variables assigned.
And..

Sum(
if date({Archive_tblEvents.TableDate}) = today
and {Archive_tblEvents.SubStatusGroup} = "Accepted - Informed Reserve"
then 1 else 0
)

/

Sum(
if date({Archive_tblEvents.TableDate}) = today
and {Archive_tblEvents.SubStatusGroup} = "Accepted - Informed Reserve"
then {Archive_tblEvents.OutstandingReserves} else 0
)

but with this it wants fields.

I think it is fairly clear what I am trying to achieve, and I bet the answer is simple.

Thanks
0
Comment
Question by:BananaFury
  • 3
  • 2
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 39762074
Create 3 formulas
Formula 1 - CntInformedRes
if date({Archive_tblEvents.TableDate}) = today and {Archive_tblEvents.SubStatusGroup} = "Accepted - Informed Reserve" then 
    1 
else 
    0

Open in new window


Formula2 - SumInformedRes
if date({Archive_tblEvents.TableDate}) = today and {Archive_tblEvents.SubStatusGroup} = "Accepted - Informed Reserve" then
    {Archive_tblEvents.OutstandingReserves} 
else 
    0

Open in new window


Formula 3 - MySummary
Sum({@SumInformedRes}) / Sum({@CntInformedRes})

Open in new window


The problem is summary formulas are evaluated over the entire recordset but that variable only has a value for 1 record.  The formula can't be evaluated for each record except as each record is handled so all the values don't exist.

mlmcc
0
 

Author Comment

by:BananaFury
ID: 39764476
That's a shame.. I was aware that this could be tackled with three separate formulas, but I was really hoping it could be handled in one. Is there no other way of dealing with such formula?
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 100 total points
ID: 39765162
You might be able to do it with running totals but it would take one for formula 1 and one for formula 2.

The problem is you are filtering the records based on data in them to determine if the should be included in the summary.  Summary functions work on ALL records and don't have a way of limiting them.

DO you need the records, the filter is eliminating from the count and sum for the rest of the report?
If not you could eliminate them through the select expert.

mlmcc
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:BananaFury
ID: 39765531
Yes, I need all the records for other areas of the report. Usually I would either use a sub report for just the records required, but having subs on reports with large tables and multiple groups isn't great, or multiple formulas, which was your approach, but that means of course if a report  needs 10 Average formulas I end up with 30 formula fields, which is painful to build and maintain.
0
 
LVL 34

Assisted Solution

by:James0628
James0628 earned 100 total points
ID: 39766102
You might be able to do it with weighted averages.  I've never really used them myself, so I'm not sure about it, but I think they might work.

 You'd still need a "count" formula for each condition, like CntInformedRes, but they don't need to set a variable.  They just need to produce a 1 if the conditions are met, or 0 if they are not.  IOW, they'd be like the first formula in mlmcc's first post.  That's your "weight".

 Then right-click on the field to be averaged (eg. OutstandingReserves), select Insert > Summary and select "Weighted average with", and then select the count (ie. weight) formula below that.  And, of course, select the summary level (grand total or whatever).

 You could give that a try.  If it works, then you've only got one "count" formula for each condition to maintain.

 James
0
 

Author Closing Comment

by:BananaFury
ID: 39778555
Thanks people. That counted weighted averages in an interesting approach. I haven't tried it so far to be honest, I just built it the way I was comfortable, but I will definitely experiment with it
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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