JMeter __counter function reference: syntax, parameters, and practical examples for parameterizing test plans with dynamic values.
Also documented in context in the full Functions and Variables reference.
TL;DR: __counter returns an incrementing integer, either per-thread (independent counters) or global (shared across all threads) โ useful for unique sequential IDs without a CSV file.
The counter generates a new number each time it is called, starting with 1 and incrementing by +1 each time. The counter can be configured to keep each simulated userโs values separate, or to use the same counter for all users. If each userโs values is incremented separately, that is like counting the number of iterations through the test plan. A global counter is like counting how many times that request was run.
The counter uses an integer variable to hold the count, which therefore has a maximum of 2,147,483,647.
The counter function instances are completely independent.
The global counter - โFALSEโ - is separately maintained by each counter instance.
Multiple __counter function calls in the same iteration wonโt increment the value further.
If you want to have a count that increments for each sample, use the function in a Pre-Processor such as User Parameters.
| Name | Required | Description |
|---|---|---|
| First argument | Yes | TRUE if you wish each simulated userโs counter to be kept independent and separate from the other users. FALSE for a global counter. |
| Second argument | No | A reference name for reusing the value created by this function. Stored values are of the form \${refName}. This allows you to keep one counter and refer to its value in multiple places. |
Example
Section titled โExampleโ${__counter(TRUE)} โ per-thread counter, starts at 1 for each thread${__counter(FALSE,cnt)} โ global counter shared by all threads, saved to "cnt"Multiple __counter calls within the same iteration donโt increment further โ only one increment per iteration, no matter how many times you reference it. If you need one increment per sample instead, put the counter logic in a Pre-Processor. For genuinely unique (not just sequential) values, see __UUID.