If you just want to display the line number in the portal you do not have to assign the value to a variable. You can just insert the record number symbol into the portal. In layout mode you would select 'Insert' from the menu then select 'Record Number Symbol'.
You can create a calculation field with get(RecordNumber) to insert into your portal. You would use the table occurrence with that calculation in your portal.
Set Variable [$Count ; Count ( PortalTable::SomeFieldThat'sNeverEmpty ) ]
will set $Count to the number of records in your portal, but only if the portal is not filtered.