Solved

Crystal Formula

Posted on 2014-01-07
6
458 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
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.

 

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

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

Title # Comments Views Activity
Combine and display field 5 73
Crystal report running 3 42
Insert timestamp data field of max summary 8 38
Crystal Reports 11 Multiple Parameters on same field 9 50
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

929 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

13 Experts available now in Live!

Get 1:1 Help Now