If you have found all the records then Get (FoundCount ) will return the number of records in the table. Otherwise it will return the number in the current found set.
If you don't want to use that then you could create a self-join relationship to the table itself, using a Constant field (eg: cConstant = 1) and then use the function
Count ( MyTable:cConstant::SelfByConstant:cConstant )
This will count every record in that relationship (ie: all records in the table) that have a value in the field cConstant (ie: every record).
"...sometimes I get the right answer and sometimes not"
To get the total record count, you'll need to use a calculation with the function Get ( TotalRecordCount ), paying attenction that that calculation must be UNSTORED ( Storage Options... of that field definition )