Crystal Reports: get access to linked elements in selection formula - crystal-reports

I'm making a report using Crystal Reports 2008 and Peachtree database. Report should display customers who didn't place orders in a last 30 days. I already figured out how to link two tables in CR with left outer join. But I wasn't able to find how that linking can be used in formulas, such as selection formula. What I am trying to achieve is to get date of last placed order for current customer and use this information to determine if customer should be displayed or not.
What is the right approach to solving this problem?

Assuming your data is setup properly and adding 'customer' and 'last order date' to the details section shows you everything, then you can just add conditional formatting formula for the suppress property of the section when 'data date - last order date < 30', leaving you only showing records where last order date is more than 30 days.

Related

Filtering a Cross Tab by a Date Range in Crystal Reporting

I've got a cross tab that sums the number of records for each month across my data set, however I don't want all of the data set. I only want the cross tab to sum the data for each of the months for records that are related to the dates between 01/01/2022 to 31/12/2022.
Normally I would set a filter on the report to say this, but I am adding another section to the report which would not work if I had that filter set. I only want the filter to apply to the actual cross tab information.
Thanks in advance!

Crystal reports - Can't filter on custom formula number field

Crystal reports don't let me use a custom count formula field to filter which transactions to show in a manager report.
I'm creating a Crystal report that team leaders are supposed to take out to see on how many occasions their employees have reported in sick. A record is only supposed to show if that person has reported in sick 6 or more times the last 12 months.
The report shows a record (a page) for each employee belonging to the managers organisational unit. Below the employee information is a subreport where I show the transactions from the salary/time system. Using select expert, I have filtered out the transactions that is supposed to show. I have then created a database field that count which day was 12 months back from today, and filtered so that only the transactions falling into this period shows.
My last problem is that I only want to show the record that has a minimum of 6 such transactions during the period. I created a formula field named #Antal ("amount" in Swedish) that simply counts the distinct number of dates in the "from"-date for the salary transactions I'm showing (since a change of law 2019-01-01 we needed to create a new transaction type, so some of the occasions after 2019 may have two transactions referring to one sick leave, thus I'm counting the first day of the period instead), DistinctCount ({P_LSTAT.P_SXXX06})
Now, the subreport has a new column with Antal (amount) that counts the amount of the desired salary transaction. I then try to use the selection formula to only show records where {#Antal} >= 6 but I get the following error:
This formula cannot be used because it must be evaluated later
Is there any other (better) way of doing this, or am I simply missing something?
For your selection based on {#Antal} >= 6 you need to use the group selection formula, not the record selection formula. Record selection is used to select records which meet the criteria before reading in the data. Group selection is used to filter out entire groups of records based on summarised values, after the records have been read in and the summaries calculated - which sounds like exactly what you need here.
The value of a Formula Field is out of scope when the Select Expert is evaluated.
There is no process for calculating the value of a Formula Field before it is printed within the section of the report it is placed. The Select Expert is evaluated prior to any section of the report being printed, so at this time all Formula Fields are effectively Nothing.

Create a chart using the records of certain type grouped by month, with a moving balance

I am trying to create a chart (bar or line) in crystal from one table in my database (Sage CRM).
The records are as follows
CustomerId Date Invoice Amount
1234 3/4/2013 Cust Invoice 3322.00
1234 3/4/2013 Payment 2445.00
1234 4/5/2013 A/c transaction 322.00
1234 5/6/2013 interest 32.00
1234 6/6/2013 payment 643.00
So I would like to have a report that meets the following criteria
Only records for the last 12 months grouped in month
Only invoice types of payment, invoice and interest
A moving balance that calculates all the invoice amounts ie
(when displaying the information for July 2012, the moving balance will be the total of all invoices prior to this date.
Without this field I can create the chart no problem using select expert but I am not sure now what to do)
Should I use a cross tab? if so how will I do the selection to only show the invoices I want and the the date range I want?
After spending almost a week on this problem, with a lot of help from an expert I have finally got a solution.
In order to create a amount that is the sum of all records for a company, month and invoice type since the beginning of time, while only displaying records for the last year, I have created a SQL command
Select
//All of the fields for the report,
movingBalance.Amount
from myInvoiceTable as mit
<join to any other tables for the report>
left join (
select customerID, sum(amount) as Amount
from myInvoiceTable
where Record_Type in ('Payment', 'Invoice','Interest')
and Date < {?Report Start Date}
group by customerID) movingBalance
on mit.customerID = movingBalance.customerID
where mit.RecordType in ('Payment', 'Invoice','Interest')
and mit.Date >= {?Report Start Date}
and mit.Date <= {?Report End Date}
There are a couple of tricks to using commands:
For performance reasons you generally want to include ALL of the data for the report in a single command. Avoid joining multiple commands or joining one or more tables to a command.
Filter the data in the command, NOT in the Select Expert in the report.
Create any parameters in the Command Editor, not in the main report. Parameters created in the report won't work in the Command Editor.
This has done the trick.
Create Date Parameters in the report to filter out the records at the time of fetching now when you run the report you have left with the data you need.
Now you can manuplate the data inside report using formula fields.
Accoding to me writing stored procedures is a bit hectic task as you can manuplate the data inside the report. I don't have any intentions to disrespect anyone opinions but frankly its my opinion.
In that case Rachsherry I would recommend the following.
For criteria parts 1 & 2 I think instead of using stored procs, it may be easier for you to use a formula.
For invoices right click the invoice field, then "Format Field" in the common tab next to the Suppress option there is a formula button, enter the following...
IF {YourInvoiceField} IN ["Payment", "Invoice", "Interest] THEN FALSE ELSE TRUE
For your date requirement you need to use a selection formula... The code for that should look something like this
{YourDateHere} > DateAdd ("yyyy", -1, CurrentDate) AND {YourDateHere} < CurrentDate
The above code basically looks at dates between the day the report is run, and exactly a year before.
For your moving balance, you should be able to achive that with the guide here
Edit - An alternative to this is to use parameter fields (Which I don't personally like) it just means having to input the parameters every time the report is refreshed, they are self explanatory but you can find a guide here

Formula for Suppressing Field if duplicate in Crystal Reports

I have a view which shows data on crystal reports where I have fields like tariff,rental,shares,gross and net.My problem is if someone changes the tariff in database it would show 2 rows of the same record with different tariff which is normal behavior from database point of view but I want to suppress the field of monthly rental to 0 if the same id has different tariff or the rental is repeated in new record.
ID Tariff Rental
1 20 390
1 15 390
I want the field of Rental on reports to be suppressed if duplicates based on id.Currently I have used this formula in crystal report to check previous field data and suppress if duplicate.
{DatabaseField}=Previous({DatabaseField})
It is working fine but if the id is not same and the rental is repeated then also it will suppress which I don't want.I want it to suppress only for same id.
You have to write the formula into field suppress. (No need on suppress if duplicated)
On Rental Field
{ID} = previous({ID}) and {rental} = previous({rental})
If ID and Rental are same then only the Report will suppress Rental.
I guess this will work for you.
In Crystal Reports, right-click on the Details section and select Section Expert.
In the Section Expert dialog box, select the X + 2 button beside the Suppress command. The check box must remain unselected for this formula to work.
In the Formula Editor dialog box, create a conditional formula containing the Next function to evaluate the records for duplicate values and to suppress the Details line
example:
{Table.Databasefield}=Previous({Table.Databasefield})
I had to make a slight change to the formula in the solution by Janarthanan by adding parenthesis to make it work with Crystal XI.
I used:
{ID}=previous({ID}) and {rental}=previous({rental})
this formatting variation, which is presented in the edited question, helped me to solve a similar problem.
Put this in suppress formula of field to hide.
if {myTable.ID} = previous({myTable.ID}) then
true
else
false

How do I order groups alphabetically?

It may be a bit more complicated then that, but here goes.
This report lists overtime on a weekly basis. Each driver has worksheets that outline details of a given shift. The user selects a period of a week, and I have some formulas that fill variables with their hours worked for each day of the week. The lines look something like this:
CKL09844 - LATTA Scott 9.5 8.6 10.5 11 0 hourlysum, etc.
The records are grouped by the 'Driver ID' - the first field - but I'd like to have them listed in alphabetical order. Only the group footers are being displayed currently. Anyone have any advice?
Edit: List them alphabetically by last name, that is.
You can either
Change the group to the 'LastName, FirstName' field or fields instead of driverID or
Use a summary to sort the group. You can do this by inserting a summary like maximum({table.name},{table.driverID}) and placing it in the footer and then suppressing it (It's stupid but Crystal needs this field actually in the report before it will allow you to access the next step). Then, go to "Report -> Group Sort Expert -> For this group sort: All" and select the summary you just made.