Scroll

Custom Function: Increment a counter

This function stores a counter during a report execution, and increments the counter by an amount every time the function is called. This can be used to track occurrences, keep a running sum of an aggregate, or just display the current row number of the report.

Note: Do not use this in a Page Header for HTML output.

Arguments (Min - Max): 1 - 1

Usage

Increment(x)

  • x is the number to add to the counter

Code:

int inc = Convert.ToInt32(args[0]);

// instantiate the counter if it does not exist
sessionInfo.GetStoredValue("counter", 0);

// increment the counter
inc += (int)sessionInfo.GetStoredValue("counter");
sessionInfo.SetStoredValue("counter", inc);

// return the value of the counter
return sessionInfo.GetStoredValue("counter");

Hidden Article Information

Article Author
Ayleesa
created 2016-01-04 23:01:08 UTC
updated 2017-06-20 19:00:08 UTC

Labels
aggregate, functions, RunningSum, example, custom function, row, number, RowNumber, RowNum, num, running, sum,
Have more questions? Submit a request