Can you be more specific? Aggregation is certainly possible but how depends on your requirements. In the script is best, unless the aggregation will depend on user selections. What do you need to achieve and can you post a sample of your app?
Actually in a table, customer id, purchase date and some other columns are there, we need to create an cutomer attrition dashboard using this table. So far that we planned to create an aggregate table as below.