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

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.

Related

Extracting most recent record in REPORT SELECTION FORMULAS GROUP. Crystal 13

I am extracting information on medication requests. For each medication request, say in the last 90 minutes, I also want to display a date for any previous time a drug was dispensed for the same patient. In many cases there will be no such history as its the first time the patient has had this drug.
I cannot seem to both show the most recent dates for those patient/drug combinations where there is a prior date but keep the records where there is no history of a prior drug being dispensed.
I have utilised Report, Selection Formulas Group as has worked in the past with different queries.
{#DispenseDT}=MAXIMUM({#DispenseDT},{#RefDRUGPATID})
NB DispenseDT is a formula joining Dispensed Date and Dispensed Time
NB RefDRUGPATID creates a unique reference for each Drug and Patient combination.
This appears to work in pulling through the most recent dispensed date/time for each DRUG/PATIENT combination. If I don't do this I get the first (oldest) record.
However, when I apply this I also lose records. I think this is because not all the DRUG/PATIENT combinations being requested have had previous records so when the formula cant find a MAXIMUM it excludes the record entirely.
I have tried doing something like if isnull({#DispenseDT}then " " else
ToText({#DispenseDT}=MAXIMUM({#DispenseDT},{#RefDRUGPATID})) but when I try and create a formula and display this I just seem to get either BLANKS or TRUE or FALSE displayed, not the "MAXIMUM" DispenseDT. It doesn't like me putting the formula within SELECTION FORMULAS GROUP either.
So in summary I am looking to pull the most recent historical dispensing date for a patient/drug combination for each new request made. But where there is no history of a drug being dispensed I still need to see the new dispensing request record.
I am using crystal reports 13.

How can I deselect an entire group based on the value of one member of the group?

We have customers that order product on an annual basis. I have a report that needs to show only customers and related orders that have NOT placed an order in the current year. I filter all orders down to the current year and the year prior.
Right now, if a customer has orders for last year, I want them to show on the report, but once the customer places an order for the current year, I want both the current year order and the prior year orders to drop off the report.
Our salespeople use this report to manage the customers that need to be contacted in the current year. Once the report is empty, they are done for the year.
I know how to suppress the rows based on the value of a single member of the group, but suppressing them does not remove them from the summary calculations, so I need them to either disappear, or I need to be able to change all values to zero for that customer once they place a new order.
Thank You.
I created a running total field to trap the current year.
If Year(#Date)=2019 then 0 else Qty
When I put the formula into a qty formula, I get the "Summary has been specified for a non-recurring field"

Crystal Reports: Accessing printed records

I've been working on a report that uses subreports to print records.
The problem is: for the same information, there may be several records - i.e.:
There may be several records for the same product if those records differ in one single column. My goal here is to make a Record Selection Formula that says: "if that item is already shown, then don't show it once again."
I've tried to use (shared) variables for this, but can't seem to find the way, because of the evaluation time.
Selection formulas are already being used to apply some filtering criteria. The column that may differ between two ocurrences of the same record is not always the same, so using a simple Selection Formula is not likely to work...
Any suggestions?
Example:
I used the record selection to tell the report:
"Show me all the products according to these criteria (warehouse=parameter1 and category=parameter2 for example)".
But there may be more than one record for the same product of the same category and inside the same warehouse, if one or more fields are different (for example, different price, different lot)
I want not to display those repetitions.
Your approach is wrong... Record Selection Forumula is something that is applied at report level not on the row level or column level.
If you requirement is not to show the records that duplicates then you need to write the supress condition for those, As per your requirement apply supress condition to the rows or columns.

Crystal Reports: Need to use a summary field as part of the Record Selection Formula

I have a fairly basic report that needs to show events with a total spend of >$200K OR event attendance >60ppl. The attendance portion is no problem, as it's a simple text field in the table. The expense spend is a field that has to be summed before it can be used, coming from a separate table with multiple entries per event. I have no problem doing this in a summary field dropped in the eventID header or even using a subreport and passing a shared variable to the main report. The problem I run into is that I cannot access this summary field in the report record selection to extract the either or records. Any idea how I can do this accurately?
Create a sql-expression field for total spending:
//{%total_spending}
(
SELECT sum(Amount)
FROM Meeting_Expenses
WHERE MeetingId=Meeting.Id
)
Use fields in record-selection formula:
{Meeting.actual_attendance}>60
AND {%total_spending}>200000

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