Grouping by Formula. A Report Design Tip.

It is helpful to remember that Crystal Reports will allow you to group by just about any formula. This allows you to create groups that are not immediately available as fields in your database tables.


For example say your boss is annoyed that your report is only displaying data by some obscure in house sku number. Getting the product description from a different table is often possible by adding the table and linking, but in some cases that data is not readily available to you.

You could instead, create a formula that parses the skus for you.

if {itemkey}="0343243" then "Widget"

else if {itemkey="0343244"} then "Coffee Can, Black"

else "Misc. Item"

The values would then show up as nice tidy groups (the groups would show up as Widget, Coffee Can, and Misc Item Naturally if you have thousands of codes you will have to find other ways).


Also note that you don't necessarily have to test for just one field! In the above example for instance, you could add another else if that checked for total sales above certain amounts, and make a handy new category. (Say your widget sold more than $1,000,000, you could have the formula return Hot Item - Widget - Sales Great than One Million or whatever would be useful.

Keeping in mind when creating a report that grouping by formula is an option, you can often provide far more flexible reports than simply using database fields!