Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula Post Reply Post New Topic
Page  of 2 Next >>
Author Message
Robcole
Newbie
Newbie
Avatar

Joined: 22 Jan 2008
Location: South Africa
Online Status: Offline
Posts: 7
Quote Robcole Replybullet Topic: Formula
     Posted: 23 Jan 2008 at 1:27am
Hi,
Can you possibly suggest anyone that can help me with a formula in Crystal Reports?
I am a complete novice and am an airline pilot by profession. It is a requirement of the local aviation authority that each pilot maintain a Flight-Time roll-back of their flight logs.
For Instance:
I have created  fields called "Flight Date", "Daily Block", 7Day Block", "30Day Block" and "365Day Block".
"Flight Date" is the flight date
"Daily Block" is the flight time of that date
 
"7Day Block" is the Daily Block (Flight Time) of the day PLUS the sum of the previous 6 days Daily Block.
 
"30Day Block" is the Daily Block (Flight Time) of the day PLUS the sum of the previous 29 days Daily Block.
 
"365Day Block" is the Daily Block (Flight Time) of the day PLUS the sum of the previous 364 days Daily Block.
 
I call the "Flight Date" and the "Daily Block" from an Acess database and all works OK.
However, I cannot create the formulas required to calculate the other fields.
 
Best Regards
Robert Cole
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 23 Jan 2008 at 2:44pm

I can think of a couple of other ways to do this.  What other fields are in your Access table? 

For example, is there a field that identifies the Pilot?  If there is, then I'll recommend one way to do this, if there's not, you'll have to take a slightly more complicated route.

-Dell

IP IP Logged
Robcole
Newbie
Newbie
Avatar

Joined: 22 Jan 2008
Location: South Africa
Online Status: Offline
Posts: 7
Quote Robcole Replybullet Posted: 23 Jan 2008 at 10:09pm

As this report is generated for each pilot, there is no filed in the Access table that identifies the pilot. However, it would be simple to add this field to the table. Each record in this field would then be one single pilots name.

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Jan 2008 at 10:07am

If you can add that field, then here's how to get your report.

1.  In the Database Expert, add additional copies of your table.  Crystal will give you a message asking if you want to alias them - click on Yes.  You'll see the table name with "_1", "_2", etc.  You want a copy of the table for each of your timeframes.  So, assuming the table is named Flight_Info, you would have the following:

Flight_Info - used for the Daily Block
Flight_Info_1 - used for the 7Day Block
Flight_Info_2 - used for the 30Day Block
Flight_Info_3 - used for the 365Day Block

2.  Link from Flight_Info to each of the other tables on the Pilot field.  DO NOT link consecutively - e.g. from _1 to _2 to _3.  All links must originate from Flight_Info.

3.  Create 3 formulas - 1 for each timeframe.  For example:

{@7Days} is {Flight_info.Flight Date} - 7

4.  In the Select Expert, select the field {Flight_Info_1.Flight Date} Is Greater Than or Equal To {@7Days}.  Do the same for the _2 >= {@30Days} and _3 >= {@365Days}.  Add these lines to whatever you're already doing to get the specific flight date.  You may have to tweak this to exclude dates that are after the flight date you're looking at from the Flight_Info table.

5.  Group on Pilot.  Place your column names in the group header section.

6.  Suppress the details section.

7.  If you're using a formula to get the flight time, create a new one for each of the other three tables.
 
8.  In the Pilot Group Footer section, use the "Insert Summary" button (it has a Sigma - funny shaped E - on it, third from the left in the bottom toolbar) to sum each of your formulas from step 7.  Sum them at the Group 1 level, NOT at the Grand Total level.
 
This should give you the information you're looking for.
 
-Dell
IP IP Logged
Robcole
Newbie
Newbie
Avatar

Joined: 22 Jan 2008
Location: South Africa
Online Status: Offline
Posts: 7
Quote Robcole Replybullet Posted: 27 Jan 2008 at 12:05am

Hi Dell,

Many thanks. However, when I try to link the tables, I get the following error "Invalid file link. Not an indexed field"

 

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 27 Jan 2008 at 5:37pm
You  need to create an Index on the Pilot field in your database......Sorry about that, it's been years since I've worked in file-based databases, most of what I'm doing these days is in Oracle and MS SQL Server where there is no index requirement for linking tables.
 
-Dell
IP IP Logged
Robcole
Newbie
Newbie
Avatar

Joined: 22 Jan 2008
Location: South Africa
Online Status: Offline
Posts: 7
Quote Robcole Replybullet Posted: 30 Jan 2008 at 10:03am
Hi Dell,
I have tried everything and am not able to create an Index on the Pilot field.
I also get an error when I try to create the formula.
You mentioned that the was another way of creating the report without having a Pilot field?
Best Regards
Robert
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 30 Jan 2008 at 3:26pm

The alternative is to create a sub-report for each flight block after the Daily one. 

- Suppress the report header and footer in the subreport.
- Make it just large enough for the data you want to display. 
- Link on the Flight Date field in the main report.
- Use your table as the data source for the subreport.
- The only object on the report will be your summary formula.
- Set the selection criteria for the subreport based on the Flight Date link.  This will look something like (for the 7 day block):
 
{table.Flight_date} <= {?Pm-table.Flight_date} and {table.Flight_date} >{?Pm-table.Flight_date} - 7
 
-Dell
IP IP Logged
Robcole
Newbie
Newbie
Avatar

Joined: 22 Jan 2008
Location: South Africa
Online Status: Offline
Posts: 7
Quote Robcole Replybullet Posted: 30 Jan 2008 at 10:10pm

Hi Dell,
I have managed to Index the Pilot Name field, included the three additional tables in my report and linked them as per your instructions.

When I create the formula, I get the following error: "The remaining text does not appear to be part of the formula" The cursor is where I have placed ().

{@7Days} ()is {FlightDetails.Date} -7

Regards

Robert

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 31 Jan 2008 at 6:42am
Try just
 
{FlightDetails.Date} -7
 
Name the formula "7Days".  When you use it it will look like {@7Days}.
 
-Dell
IP IP Logged
Page  of 2 Next >>
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum