Link to home
Start Free TrialLog in
Avatar of BananaFury
BananaFury

asked on

Crystal Formula

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
Avatar of Mike McCracken
Mike McCracken

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
Avatar of BananaFury

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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