I use SQL. If the dataset is one-way, calculating value by value with first/next I think is ok.
If the dataset is in memory, for large data sets, it will not cope,
For large data sets, I mainly use the SQL version because filters / stored procedures can be used for efficient filtering.
I don’t know how it works on other databases, but for FirebirdSQL in the case of SQL, an option would be:
SELECT
COUNT(*) as ColumnALL
FROM (
{All SQL content with joins, parameters and dynamic sql as is edited}
)