Hello,
I’m using AgGrid in Streamlit to display a table where CPA (Cost per Call) is calculated as Cost / Calls
. At the individual campaign level, the calculation is correct, but when I group data (e.g., by account), AgGrid applies default aggregation functions like sum
or avg
, which results in incorrect values. Instead of recalculating CPA as Total Cost / Total Calls
, AgGrid aggregates the existing CPA values, leading to misleading results.
I have tried precomputing an “Aggregated CPA” column in Pandas before displaying the data and using valueGetter
in AgGrid to enforce Cost / Calls
, but these solutions do not apply correctly when data is grouped dynamically. I also attempted custom aggFunc
functions, but I haven’t found a way to force AgGrid to recalculate CPA at each aggregation level. How can I ensure that CPA is always computed as Total Cost / Total Calls
at all grouping levels instead of using incorrect aggregation methods?