Click here to Skip to main content
15,868,292 members
Articles / Database Development
Tip/Trick

Crystal Reports User Group Selections

Rate me:
Please Sign up or sign in to vote.
4.50/5 (5 votes)
6 May 2010CPOL 16.4K   4   1
This is a great to allow users control over their reports and cutting down on the volume of reports needed to meet the business’s needs.The basis of this solution is to control which fields are grouped on within the report which will in turn change the summary operations and change the...
CSS
This is a great to allow users control over their reports and cutting down on the volume of reports needed to meet the business’s needs.

The basis of this solution is to control which fields are grouped on within the report which will in turn change the summary operations and change the entire context of the report.

The following tutorial uses the Xtreme Access database which ships with Crystal Reports and allows the resulting report to focus on order values by either; City, Region or Country.

1. Create a Report with the following Tables: Customer, Invoice and Orders.

2. Add the Fields; Customer ID, Customer Name, ‘City’, ‘Region’ and ‘Country’.

3. Reach agreement with the User as to the Fields they want the option to Group the Report on.  In this case we are going to use ‘City’, ‘Region’ and ‘Country’.

4. Create a Parameter called prmSelectGroup.  Provide the User with three, discrete, options; ‘City’, ‘Region’ and ‘Country’.

5. Create a Formula called frmGroup and enter the following code:

SELECT {?prmSelectGroup}
CASE "City":
   {Customer.City}
CASE "Region":
   {Customer.Region}
CASE "Country":
   {Customer.Country};

6. Insert a Group into the Report based on the frmGroup Formula.

7. Insert a Distinct Count Summary on the Customer ID and Grouped by frmGroup.

Now refresh the Report and select a Group option from the Parameter.  Both the Group changes and the Summary Field based on this Group.
However, there is a problem in that the Field chosen to Group by is still in the Detail Section.  This is not always the case, and may not be a problem when it is, but for the sake of neatness we shall make the potential Group Fields dynamic.

8. Remove the Fields ‘City’, ‘Region’ and ‘Country’ from the Report.

9. Create four Formula Fields, frmField01 and frmField02, frmHeader01 and frmHeader02.

10. The intention is to display whichever two of the three haven’t been picked for the Group.  In frmField01 enter the following Formula:

SELECT {?prmSelectGroup}
CASE "City":
   {Customer.Region}
CASE "Region":
   {Customer.Country}
CASE "Country":
  {Customer.City};

And the same again for frmField02, but with the values moved around by one place:

SELECT {?prmSelectGroup}
CASE "City":
   {Customer.Country}
CASE "Region":
  {Customer.City}
CASE "Country":
   {Customer.Region};

11. A similar Formula is used in frmHeader01 for the Field Header:

SELECT {?prmSelectGroup}
CASE "City":
   "Region"
CASE "Region":
   "Country"
CASE "Country":
  "City";

And the same again for frmHeader02, but with the values moved around by one place:

SELECT {?prmSelectGroup}
CASE "City":
   "Country"
CASE "Region":
  "City"
CASE "Country":
   "Region";

12. Add frmField01 and frmField02 to the Detail Section and the frmHeader01 and frmHeader02 to the Page Header Section.
Refreshing the Report and selecting a different Parameter option will cause the Group to change and the two Fields not chosen to appear in the Detail Section.

About the Author

Jason Dove is the author of "Crystal Reports Formulas Explained&", a step by step guide to creating and using formulas, currently available with a free 70 page Crystal Reports XI tutorial: <a>http://www.scry-business-intelligence.com/products/bookoffer.php<a />

He has provided BI consultancy for some of the largest companies in the UK, and is now working with Scry Business Intelligence. Subscribe to his FREE Career newsletter here: <a>http://www.scry-business-intelligence.com/ScryCareerGuide.php</a></a>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Scry Business Intelligence
United Kingdom United Kingdom
Jason Dove is a senior consultant at Scry Business Intelligence and instructor who has specialised in Crystal Reports and Business Intelligence his entire career, utilising it for everything, from selling paint to counter-terrorism. He has provided Business Intelligence consultancy for some of the world’s leading companies and is currently making the same service available to smaller businesses. He is also the author of 'Crystal Reports Formulas Explained', a step by step guide to creating and using formulas for the industry leading BI reporting software.

Comments and Discussions

 
GeneralMy vote of 1 Pin
kh2tech21-Oct-13 11:41
professionalkh2tech21-Oct-13 11:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.