division between sums considered fast search

Good morning,I have a table called ‘movimenti_vendite’ and in this table I have 2 columns called ‘Totpeso’ and ‘Imponibile’. These 2 columns have the aggregate function activated to be able to display the sum.

The sum in question allows me to display the sum of the values ​​in the columns both if I don’t use the quick search filter and if I perform a quick search and in the latter case the sum corresponds to the sum of only the values ​​visible after the quick search.Now I have a problem: I created a column called Mediat where I would like to display the result (even on each row is fine) of the following formula: Sum of Imponibile / Sum of Totpeso.I have used both the custom filed and the event servers but I can only display the result of the sum of all the rows and never only those remaining from the quick search. Is there a way to perform the division taking as a reference the sums of only the visible rows? I tried these 2 codes but they don’t work.Can anyone help me? I just need to know if there is a way to do what seems to be a simple division.Thanks again.

// Page Load event
function Page_Load()
{
    // Controlla se la pagina è una lista
    if ($this->PageID == "list" && !$this->isExport()) {
        // Inizializza variabili per la somma
        $totalImponibile = 0;
        $totalTotpeso = 0;

        // Recupera i record
        $sql = $this->GetSQL($this->CurrentFilter, $this->getOrderBy());
        $rs = $this->getConnection()->query($sql); // Usa query per eseguire la query

        // Verifica se ci sono record
        if ($rs && $rs->rowCount() > 0) {
            while ($row = $rs->fetch()) { // Usa fetch per ottenere le righe
                // Somma i valori di Imponibile e Totpeso
                $totalImponibile += $row['Imponibile'];
                $totalTotpeso += $row['Totpeso'];
            }
            // Chiudi il recordset
            $rs = null; // Rilascia la connessione al recordset
        }

        // Calcola la media se Totpeso non è zero
        if ($totalTotpeso != 0) {
            $media = $totalImponibile / $totalTotpeso;
        } else {
            $media = 0; // Evita divisione per zero
        }

        // Imposta il valore nel campo Mediat
        $this->Mediat->CurrentValue = $media; // Assicurati che Mediat sia il nome corretto del campo
    }
}

or custom field expression:

	(SELECT SUM(Imponibile))/(SELECT SUM(Totpeso))

That is because you did it in Page_Load which is fired on page load, before the search criteria is handled. You should do it in Page_Render.