Search code examples
crystal-reportscrystal-reports-xi

Change Group Name in Crystal Reports to non-Database Value using Formula


I am looking to change the group names in a crystal report to a specified text value not located within the database.

e.g. i have a 'status' field that can either be 'i' or 'a'. I would like these to display as 'inactive' or 'active' in the group headings. The code i currently have in the 'Use a formula as group name' is:

stringvar newGroupName;
if (groupname = "I") THEN newGroupName:= "Inactive" ELSE
if (groupname = "A") THEN newGroupName:= "Active" ELSE
newGroupName:= groupName;
newGroupName

However this says i am passing too few arguments for the groupName reserved word.

Have looked on the net but have not found anything for defining non database names using the groupname function. Any help greatly appreciated.


Solution

  • Just to add, I always add a standard formula to the formula list to calculate the group names :

    if {table.field} = 'I' then
        'inactive'
    Else if {table.field} = 'a' then
        'active'
    Else
        'unknown'
    

    Then in the group name formula in the group expert I refer to the formula like {MyGroupName}

    This makes it much easier and quicker to edit the names but also will not be lost if you edit the group field (very useful if you have a large amount of code).