A look at SAP Crystal Reports for Visual Studio 2010
page 5 of 6
by Vince Varallo
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 35818/ 90

Dynamic Grouping

The last feature this article will demonstrate is how to use the parameter panel to change how a report is group at runtime.  By allowing the user to change groups at runtime they can see summations, counts, and averages based on the groups without having to create separate reports for each group. 

1.    Stop the debugger if it is running.  Right click on the Parameter fields in the Field Explorer and select New…

2.    Enter "Group By" for the name of the formula.

3.    In the Value Grid enter "City", "State\Province", and "Hire Date (Year)".

4.    In the Value Options grid, change the Allow Custom Values setting to false.

5.    Click the OK button.

6.    Right click on the Formula Fields in the Field Explorer and select New… from the pop-up menu.

7.    Enter "Grouping Field" for the name and click the OK button.

8.    Enter the following formula:

if {?Group By} = "City" then
    {Address.City}
else if {?Group By} = "State\Province" then
    {StateProvince.StateProvinceCode}
else if {?Group By} = "Hire Date (Year)" then
    totext(Year({Employee.HireDate}), "####")

9.    This will resolve what the user has entered into the correct database field or formula.

10. Click the Save and close button.

11. Now you need to add a group that groups by this formula.  Right click on the white space in the report and select InsertàGroup from the pop-up menu.

12. Set the condition field to the "Grouping Field" formula and click the OK button.

13. The group should now be added to the report and a group header and footer section should appear in the design of the report.

14. Now add a count to the group header.  When you preview the report and change how the grouping works this number should change.

15. Right click on the Last Name field in the Details section.

16. Select InsertàSummary from the pop-up menu.

17. Change the "Calculate This Summary" drop down list to "Count".

18. Change the "Summary Location" drop down list to "Group #1:GroupingField - A".

19. Click the OK button.  This will add the count to the group footer section.  Drag the field to the group header section.

20. Run the report again.  This time enter a start date of 1/1/2000 and an end date of 12/31/2001.  Set the grouping field to City.  Your report should look like the following image.

21. Display the Parameter Panel by clicking on the (?) on the left side.  Change the group to Hire Date (Year) and click the Apply button.

The report should now be displayed grouped by the year of the employee's hire date.


View Entire Article

User Comments

Title: Need another sample   
Name: Matt Slay
Date: 2010-07-21 5:29:44 AM
Comment:
Nice intro showing how it all from within CR, but I'd like to see a sample where I had data from a LINQ query (EF or Linq To Sql) or even DataTables, where the querying and filtering happens in code inside my DAL, and then how that data can be passed into the report.

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-10-25 1:26:28 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search