?
Solved

Crystal Formula

Posted on 2014-01-07
6
Medium Priority
?
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 101

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 101

Accepted Solution

by:
mlmcc earned 300 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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 

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 35

Assisted Solution

by:James0628
James0628 earned 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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