AMPscript RowCount (Next)
Count the rows of a rowset with AMPscript RowCount in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email.
Syntax
RowCount(rowset) → number
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
rowset |
rowset | Yes | A rowset from LookupRows, LookupOrderedRows, ExecuteFilter, or a BuildRowsetFrom* function |
Example
%%=RowCount(BuildRowSetFromString("a::b::c", "::"))=%%
Renders 3.
Because an empty rowset gives 0 rather than an error, it is the guard to use before reading a row:
%%[
SET @rows = RetrieveSalesforceObjects("Contact", "Id", "IsDeleted", "=", "false")
IF RowCount(@rows) > 0 THEN
SET @idLength = Length(Field(Row(@rows, 1), "Id"))
ENDIF
]%%
%%=v(@idLength)=%%
Renders 18.
Return value
number — how many rows the rowset holds, 0 for an empty one.
Behaviour
Counts the rows. RowCount(BuildRowSetFromString("a::b::c", "::")) gives 3; a multi-character delimiter works.
A string without the delimiter is one row. RowCount(BuildRowSetFromString("NoDelimiterHere", ",")) gives 1.
An empty rowset gives zero. RowCount on BuildRowsetFromJSON("[]", "$[*]", 1) renders 0, and so does RowCount on a RetrieveSalesforceObjects query that matches no record. Neither fails.
Show Next test script
<!-- Marketing Cloud Next test script for RowCount. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[3] got=[%%=RowCount(BuildRowSetFromString("a::b::c","::"))=%%]</p>
<p>c2 expect=[1] got=[%%=RowCount(BuildRowSetFromString("NoDelimiterHere",","))=%%]</p>
<p>c3 expect=[0] got=[%%[ SET @c1rs = BuildRowsetFromJSON("[]", "$[*]", 1) ]%%%%=RowCount(@c1rs)=%%]</p>
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
Engagement gives the same counts: 3 for a split string, 1 for a string without the delimiter and 0 for an empty rowset. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
RowField— read a counted rowsetRetrieveSalesforceObjects— produces a rowset to count- Official reference