Creating and Using User-Defined Functions |
function CalculateCommission(SaleAmount)
do case
case SaleAmount >= 1000
Commission = SaleAmount * 0.12
case SaleAmount >= 500 and SaleAmount < 1000
Commission = SaleAmount * 0.10
case SaleAmount >= 100 and SaleAmount < 500
Commission = SaleAmount * 0.08
otherwise
Commission = 0
endcase
return CommissionTo use this UDF in a commission report, create a new report and add the desired fields, including the sale amount field. Then, turn on the Advanced layout option and click Edit to bring up the Advanced Report Designer. Create a new field and enter the following for the field's expression:
CalculateCommission(ARITRS.NSALESAMT)
ARITRS.NSALESAMT is the name of the field in this example that contains the sale amount. Alternately, instead of having to type the field name, you can click the Expression Builder button, type "CalculateCommission(", select the AR Invoice Line Items table, double-click the Subtotal Amount field to add it to the expression, then type a closing ")".
Enter 999,999.99 for the Format and then click OK. To create a subtotal of commissions by user, copy the field and paste it, then move the copy to the group footer. Double-click the copy, select the Calculate page, and choose Sum from the Calculation type option. Save and run the report.