Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula for calculation gives incorrect result

Status
Not open for further replies.

lndoan

IS-IT--Management
Jun 30, 2005
28
US
I have the following formula:

Whileprintingrecords;
Numbervar extra;

If {Trips.Trip Date} = {?TripDate} and {TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO} = "EXTRA" then
extra := Count ({TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO})
else
0

This is in the detail section with all other working formulas.

The field {TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO} consist of different schedule types and one of them is EXTRA. I need to find all the schedule types EXTRA for every train everyday and if EXTRA exist, i want to count the number of EXTRA trains there are in a day.

My display formula is:
//{Display}
whileprintingrecords;
numbervar extra;

this is in the report footer

What am i doing wrong?
 
Group by the {Trips.Trip Date} (Insert->Group)

Insert a Running Total to do a count of the {TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO}, grouped by the date, and in the Evaluate->Use a formula place:

{TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO} = "EXTRA",

-k
 
Or you could remove the whileprintingrecords and the variable from your original formula and change it to be:

If {TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO} = "EXTRA" then 1

You should have a group on {Trips.Trip Date} and then right click on the above formula and insert a summary (SUM, not count). This assumes you have no row inflation. If you do, then you need to use a running total as SV suggested.

-LB

 
In the group header for route id, i have the following formula showing so i can see the calculated numbers using the formula:

If {TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO} = "EXTRA" then
count ({TRIP_MAIN_OPS.SCHTYP_SCHEDTYPE_NO},{Trips.Trip Date}, "daily")
else
0

This formula shows the correct calculation.

I cannot click on the sum and sum this formula call @extra, it is not on the list. If i try using a formula Sum ({@extra}) it tells me that this is not summable.

 
You can't perform an aggregate function on a formula containing an aggregate function.

You'll need another set of formulas, as in:

Group footer formula:
whileprintingrecords;
numbervar MySum:=MySum+{@extra}

Now in the report footer or an outer grouping you can refer to it using:

whileprintingrecords;
numbervar MySum

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top