You can try below linked details for the issue mentioned by you.
https://docs.preset.io/docs/using-jinja-to-manipulate-the-aggregated-column-used-on-a-chart