Print Page | Close Window

Grouping report at runtime

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=1534
Printed Date: 02 May 2024 at 6:44am


Topic: Grouping report at runtime
Posted By: Alexeixx3
Subject: Grouping report at runtime
Date Posted: 19 Oct 2007 at 1:39pm
Hi all
Can anyone tell me how to perform grouping of a crystal report
 
The field to group on is variable (selected by the user at runtime)
 
If anyone has any axamples, please let me know
 
Thank you



Replies:
Posted By: hilfy
Date Posted: 21 Oct 2007 at 9:31am
I assume the user is selecting the group based on a parameter.  So, this is actually fairly easy.
 
Create a formula that looks something like this (not know what your groups are, I'm writing this base on my data):
if {?GroupName} = 'Loan Number' then
  {loan.loan_number}
else if {?GroupName} = 'Property State' then
  {loan.property_state}
else if {?GroupName} = 'Posting Date' then
  ToText({loan.posting_date}, 'yyyyMMdd')
All of the results have to be in the same format - string, number, etc. - so you may have to do some conversion based on the field type.   So, you can see that I converted the date field to text.  When you're working with dates that have been converted to text, you have to format them differently when you're using them to sort data than if you're just displaying them because they'll sort in text order instead of in date order. 
 
Once you have your formula set up, use that as your group instead of a specific field.
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Alexeixx3
Date Posted: 26 Oct 2007 at 7:33am
Hey hilfy thanks a lot for your answer
I just tried it and it works great!!!
 
I was trying to figure out how to set the grouping on a date field by year, month, week, day, hour and so on
Ive used this option but not at runtime, that option is the one available when you click the options... button in the group expert
If you or anyone else could give a clue or something
Ill appreciate it
 
 
Thanks


Posted By: hilfy
Date Posted: 26 Oct 2007 at 7:54am

You should be able to use the same ToText technique that I explained above. 

Year would be: ToText({datefield}, 'yyyy')

Month: ToText({datefield}, 'yyyyMM')

etc.  Look at the Help for ToText to see all of the date formats.  Please note that the format string is case sensitive - month is 'MM' not 'mm'.

-Dell



-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Alexeixx3
Date Posted: 31 Oct 2007 at 12:21pm
Thanks a lot hilfy



Print Page | Close Window