Total sum of a column using virtual column in streamlit-aggrid

Hi guys, i need a help in aggrid

Basically i want to build a streamlit to help me rebalance portfolios.

So far i got a pretty good result in showing the data of the portfolio diveded by asset classes. And the result of new investment in individual assets (collumns “APLICACAO” and “RESULTADO”
Here is a print of what it look like so far.

The problem is that i want the (%) to be dinamic, the one showing is based on the pandas calculation that i did before, so it does not change with nem applications

Here is the code for it.

gb.configure_column(field="FUNDO", header_name="FUNDO", width=300, rowGroup=True, hide=True)
gb.configure_column(field="SUB_TIPO", header_name="SUB_TIPO", rowGroup=True, width=400, hide=True)
gb.configure_column(field="NOME COMERCIAL", header_name="NOME COMERCIAL", width=300)
gb.configure_column(field="FINANCEIRO", header_name="FINANCEIRO", type=["numericColumn"], aggFunc="sum", 
                    pivot=True, width=200, valueFormatter="'R$ ' + value.toLocaleString()")
gb.configure_column(field="APLICACAO", header_name="APLICACAO", editable=True, type=["numericColumn"], 
                    aggFunc="sum", pivot=True, width=200, valueFormatter="'R$ ' + value.toLocaleString()")
gb.configure_column(field="%", header_name="%", type=["numericColumn"], aggFunc="sum", pivot=True, width=200, valueFormatter="value.toLocaleString() + ' %'")
gb.configure_column(field="RESULTADO", header_name="RESULTADO", valueGetter='(Number(data.FINANCEIRO) + Number(data.APLICACAO))', 
                    cellRenderer='agAnimateShowChangeCellRenderer', editable='false', type=['numericColumn'], aggFunc="sum", valueFormatter="'R$ ' + value.toLocaleString()")

My first guess was to look at the valueGetter documentation, to do something like ‘(Number(data.RESULTADO) / Number(data.RESULTADO).sum())’, but i did not find nothing. Someone already had to do something like this?

Grateful in advance.


With the help of Pablo, i could get to a closer result.

Basicaly what i wanted was the weight of each asset after a new investment (more money)

So the solution was to create a new column using in the valueGetter: node.parent.parent.aggData

valueGetter=“(Number(data?.FINANCEIRO) + Number(data?.APLICACAO)) / (Number(node.parent?.parent?.aggData?.RESULTADO)) || 0”,

FINANCEIRO is the inicial value invested in the asset
APLICACAO is the value of the new investment
node.parent.parent.aggData.RESULTADO is the sum of the RESULTADO column.

However i found a new bug “aggFunc=“sum”” does not update for values outside the pivot group. Im working on it.