Search code examples
crystal-reportsformattingconditional-statementscrystal-reports-2008crosstab

For each crosstab column, highlight maximum value


I'm trying to highlight the maximum value in a Crystal Reports crosstab column, per column, i.e. show the best performing salesman in each month.

It seems like a fairly basic requirement, but I can't figure it out! The Highlighting Expert would seem to be the obvious answer, but it only works if you have defined criteria (e.g. Gross Sales > 120,000), and I'm not interested in highlighting the Totals at the end of the columns/rows....I just want the highest value row per column.


Solution

  • This is much more difficult than it needs to be...

    Add this text to the summary field's "Tool Tip Text" conditional-formatting formula:

    // this assumes that there is a Total column and that it is the left-most column.
    
    Numbervar max:=0;
    local Numbervar col;
    
    // exclude (left-most) total column
    for col := 1 to GetNumColumns-1 do (
    
        local numbervar value := GridValueAt (CurrentRowIndex, col, CurrentSummaryIndex);
        if value > max then max := value;
    
    );
    
    ToText(max,"#");
    

    Then add this text to the same field's "Style" conditional-formatting formula:

    Numbervar max;
    
    If GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0) = max Then
        crBold
    Else
        crRegular