Formula fields within Crystal Reports allow you to inject
code blocks within a report when simple Select SQL statements can't do the
trick. You can declare variables, create if-then blocks, create arrays,
execute loops, or call built in functions within Crystal Reports. This article
will create a Crystal Report in an ASP.NET web site project and demonstrate how
to create a formula field, manipulate a date in the formula as well as
elaborate on how to declare a variable and assign it a value, and also use if-then
logic to create summary fields by quarter on the report.
Before you begin you will need to have installed Visual
Studio 2008 with Crystal Reports for .NET. The samples are written in Visual
Studio 2008 but they will work with Visual Studio 2005 also. I created a simple
database with one table to use for the sample report. The code for the sample
report created in this article can be found here.