Monday, January 30, 2012

Crystal Reports : Creating a Verbose value from a "Code"

In many instances, you'll be reporting from a series of Codes. Let's imagine that we are Grouping a report on {ORDERS.PRODUCTCODE}, which is a three character value denoting the type of Product sold.

Values are:

- WID (Widget 5000)
- SRV (Professional Services)
- MSC (Miscellaneous)

But now let's imagine the Boss wants to see the actual Type Names on the report (so, instead of WID he wants to see "Widget 5000".

This is easily done with a simple Formula:

1. From your Field Explorer, right click on "Formulas" and select New.

2. Give your new Formula a descriptive name like {@frmProductCode}.

3. Paste in the following text:

IF {ORDERS.PRODUCTCODE} = "SRV" THEN "Professional Services" ELSE
IF {ORDERS.PRODUCTCODE} = "MSC" THEN "Miscellaneous" ELSE "Unknown"

4. Now simply Save and Exit the Formula Editor, and place the new Formula on your report. Note the final ELSE kicks out "Unknown", so if someday someone mistakenly entered in "MSV" (fat fingering the "C") for Miscellaneous, we will get an "Unknown" on the report, making it way for us to determine what happened.

No comments: