How to: Redesign Section Triggers that Calculate Percentage

Microsoft Dynamics Nav 2009

On some reports that show percentages, the function that calculates the percentage is on one or more section triggers. In client report definition (RDLC) report layouts, code on section triggers is not supported. You must add a function to the report to calculate the percentage and modify fields in the Report.rdlc file so that they call the function. For example, in the standard application, report 113, Customer/Item Sales, uses the CalcPct function to calculate profit percentages.

Before you begin this procedure, you must create a layout suggestion for the report. For more information, see How to: Create a Layout Suggestion.

To transform section triggers that calculate percentage

  1. In the Classic client, on the Tools menu, click Object Designer.

  2. In Object Designer, click Report, select a report that you want to modify, and then click Design.

  3. On the View menu, click Layout.

  4. In Microsoft Visual Studio, in the Report.rdlc file, on the Report menu, select Report Properties.

  5. In the Report Properties window, select the Code tab.

  6. Add the following code in the Custom code text box:

        Shared Pct As Decimal 
        Public Function CalcPct(ByVal Amount As Decimal, ByVal Profit As Decimal) As Decimal 
            If Amount <> 0 Then
                Pct = 100 * Profit / Amount
                Pct = 0
            End If
            REM Rounding precision = 0.1
            Return ROUND(10 * Pct) / 10
        End Function

    This code is also available in report 113, Customer/Item Sales.

  7. Click OK.

  8. In Visual Studio, in the Report.rdlc file, right-click each text box to display a percentage, and then click Expression.

  9. In the Expression window, enter the following expression:


    The amount and profit parameters that you pass to the CalcPct function are lookup values from the Microsoft Dynamics NAV table.


    In report 113, Customer/Item Sales, the expressions in the Profit % column, which is the column on the right of the report, call the CalcPct function. For example, the first expression in the column is =Code.CalcPct(Fields!ValueEntryBuffer__Sales_Amount__Actual___Control44.Value, Fields!Profit_Control46.Value).

  10. Click OK.

See Also

Community Additions