2024 Apr 08 10:40 PM - edited 2024 Apr 08 10:51 PM
My report is grouped by status and sorted by the status column. Through the UI the grouping functionality accepts only one column as the criteria. How can I filter based on a combination of criteria?
Records to display in the first section (active or under renewal) if: Status is Active or (status is Renewal AND the expiration date is more recent than the last 12 months).
Records to display in the second section (Expired) if: Status is Expired or (status is Renewal AND the expiration date is older than 12 months ago from today).
Request clarification before answering.
Hi ReportingMil, are you using the full / standalone version of Crystal Reports? If so create a new formula and write out the logic that you mention but use Crystal formula syntax...not sure how that would be written as there is no indication on what fields determine status, expirations, etc. Afterwards, right click on the existing Group Header and choose Change Group and then use your new formula instead.
if {your status field} in ["your active value", "your renewal value"]
then "Active or Under Renewal"
else if {your status field} = "renewal" and datediff("d",{your experiration date},currentdate) > 365
then "Expired"
else "Your Default Value"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi JWiseman, thanks for your reply. I am using SAP Crystal Reports 2016 Support Pack 6 Version 14.2.6.2839. Product Type: Full.
Formula for the first group: If {Table1.status} startswith 'Renewal' And {Table1.ST_LIC_EXPIRE} in DateAdd("yyyy", -1, CurrentDate) To CurrentDate Then True Else False.
Thanks for the tip on using the Change Group Option. When I select Use a Formula as Group Sort Order, it takes me to the Current Formula Folder X-1 Group Sort Order Formula. However, even though the formula I stated earlier was accepted in the Formula Fields folder, I receive an error pasting it in the Group Sort Order Formula section that {Table1.status} needs to be a constant expression.
The above should return records that meet those criteria. Then I want the next set of records that are expired to show in the next section of the report (the second criteria from my initial posting.
The suggestion was to use a Formula as the Group vs using it in the Group Sort Order.
This is really helpful. I am getting this, but can't see something wrong with the formula:
A number, currency amount boolean, date, time, date-time, or string is expected here. I checked the format of the expiration date/time, and it seems to be a Crystal accepted format. Sample: 2022-10-01 00:00:00.000
if {Table1.status} = "ACTIVE" then
"Active or Under Renewal Process"
else if {Table1.status} = "RENEWAL PROCESS" then
if DateDiff("d", {Table1.ST_LIC_EXPIRE}, CurrentDate) < 365 then
"Active or Under Renewal Process"
else
"Expired" else "Unknown Status"
In your formula on the 3rd to 4th line there's a "then if"...I'm guessing that you want an "and" there. Also at the end you've got 2 different default "else" conditions. I've commented out the last one...let me know how you want the logic to work for the grouping formula.
if {Table1.status} = "ACTIVE"
then "Active or Under Renewal Process"
else if (
{Table1.status} = "RENEWAL PROCESS" and
DateDiff("d", {Table1.ST_LIC_EXPIRE}, CurrentDate) < 365
) then "Active or Under Renewal Process"
else "Expired"
// else "Unknown Status"
The report is running now. However, the result is showing ST_LIC_EXPIRE greater than 365 days as "Active or Under Renewal Process", instead of Expired.
if {Table1.status} = "ACTIVE" then "Active or Under Renewal Process"
else if {Table1.status} = "RENEWAL PROCESS" then if datediff("d", {Table1.ST_LIC_EXPIRE}, currentdate) < 365 then "Active or Under Renewal Process"
else "Expired"
Sample:
In line 2 are you trying to satisfy 2 conditions? If so try using an "and" instead...i.e.
if {Table1.status} = "ACTIVE"
then "Active or Under Renewal Process"
else if {Table1.status} = "RENEWAL PROCESS" and datediff("d", {Table1.ST_LIC_EXPIRE}, currentdate) < 365
then "Active or Under Renewal Process"
else "Expired"
Also if you get these kinds of issues you might want to consider creating a test formula to test each line...
Getting really close. The data is now showing in the Preview tab. However, when running in the test environment, I am still getting:
Formula:
if {Table1.status} = "ACTIVE"
then "Active or Under Renewal Process"
else if {Table1.status} = "RENEWAL PROCESS" and datediff("d", {Table1.ST_LIC_EXPIRE}, currentdate) < 365
then "Active or Under Renewal Process"
else "Expired"
Below is what it's showing me. I keep deleting the "or" at the end of the third line and it keeps coming back.
if IsNull ({@Sorting})
then 0
else if {@Sorting} = "ACTIVE or UNDER RENEWAL PROCESS" or
then -3
else if {@Sorting} = "EXPIRED"
then -2
else
User | Count |
---|---|
73 | |
21 | |
8 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.