How to use aggregations on the fly