SIGN UP MEMBER LOGIN:    
ARTICLE

Crystal Reports User Group Selections

Posted by Jason Dove Articles | Crystal Reports C# March 25, 2010
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.
Reader Level:

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.

Login to add your contents and source code to this article
Article Extensions
Contents added by Jason Dove on Apr 16, 2010
Jason Dove is the mastermind behind the revolutionary Scry Career Primer, the only product on the market dedicated to launching your IT career, covering everything from gaining industry experience and writing a killer résumé to exploiting the most popular IT sectors.
Contents added by Jason Dove on Mar 30, 2010


crystal_reports_formulas_explained.jpg

Working with Crystal reports and find formula writing confusing? There’s finally a book which sets out to redress the balance and provides the first step by step guide for creating and using formulas, for all versions of Crystal Reports, which is aimed at people with little or no programming knowledge.

‘Crystal Reports Formulas Explained’ is currently available with a free 70 page Crystal Reports XI tutorial!


share this article :
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor