RowCount
Returns the number of rows in a rowset. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including that it returns zero for an empty rowset and never aborts.
Syntax
RowCount(rowset) → number
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
rowset |
rowset | Yes | A rowset from LookupRows, LookupOrderedRows, ExecuteFilter, or a BuildRowsetFrom* function |
Example
%%[
VAR @rows
SET @rows = LookupRows("AMP_VERIFY_SCRATCH", "FirstName", "Alice")
]%%
Matches: %%=v(RowCount(@rows))=%%
With two Alice rows, renders Matches: 2.
Because it returns 0 rather than aborting on an empty rowset, it is the safe guard before reading any row:
%%[
VAR @rows
SET @rows = LookupRows("AMP_VERIFY_SCRATCH", "FirstName", "Alice")
IF RowCount(@rows) > 0 THEN
]%%
First: %%=v(Field(Row(@rows, 1), "Id"))=%%
%%[ ENDIF ]%%
Return value
number — the count of rows in the rowset, 0 for an empty one.
There is no sentinel: the result is a bare non-negative integer.
Behaviour
Counts the rows in a rowset. A populated rowset from LookupRows("AMP_VERIFY_SCRATCH", "FirstName", "Alice") returned 2.
Returns zero for an empty rowset and never aborts. RowCount(LookupRows("AMP_VERIFY_SCRATCH", "FirstName", "Zoltan")) returned 0, making it the correct pre-read guard when a lookup may match nothing.
Show test script
%%[
VAR @b
SET @b = RequestParameter("b")
IF @b == "zzz" THEN
OutputLine(Concat("CTRL=[alive]"))
ENDIF
IF @b == "safe" THEN
DeleteData("AMP_VERIFY_SCRATCH", "Id", "A1")
DeleteData("AMP_VERIFY_SCRATCH", "Id", "A3")
InsertData("AMP_VERIFY_SCRATCH", "Id", "A1", "FirstName", "Alice", "Score", 10)
InsertData("AMP_VERIFY_SCRATCH", "Id", "A3", "FirstName", "Alice", "Score", 30)
/* count of a populated rowset */
OutputLine(Concat("RowCount(match)=[", RowCount(LookupRows("AMP_VERIFY_SCRATCH", "FirstName", "Alice")), "]"))
/* count of an empty rowset - returns 0, never aborts */
OutputLine(Concat("RowCount(empty)=[", RowCount(LookupRows("AMP_VERIFY_SCRATCH", "FirstName", "Zoltan")), "]"))
ENDIF
]%%
OutputLine given a bare string literal renders an empty line. Wrap the argument in Concat() or your start and done markers vanish silently — which looks exactly like the function failing.
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
See also
LookupRows— produces the rowset to countRow·Field— read a counted rowsetDataExtensionRowCount— counts every row in a data extension by name- Official reference · ampscript.guide