When to execute a function?

Hi, I have a couple functios that need to be executed after a dataset filter, however I am having trouble executing them automatically, probably because of the filter lag, I have already tried .then or await/async but istill not able to acomplish this.

I know my functions are working correctly because I can trigger them lets say by an on click event handler or anything else.

The question is, how can I correctly execute those 2 functions after the filter has finished loading the data?

Here is the code:


import wixData from 'wix-data';
import { fmt } from 'public/currency.js'

$w.onReady(function () {
 let today = new Date()
    today.setHours(0, 0, 0, 0);
    $w("#cargosDS").setFilter(wixData.filter()
        .eq("fecha", today)
    );
});

function totales(event) {
    $w('#cargosDS').refresh();
 let allRows = $w("#cargosTABLE").rows;
 let total = 0;
 let pago = 0;
 let balance = 0;
    allRows.forEach((row) => {
        total += Number(row["total"]);
        pago += Number(row["pago"]);
    })
    $w("#totalLabel").text = "" + fmt(total);
    $w("#pagoLabel").text = "" + fmt(pago);
    balance = total - pago;
}

function formato(event) {
 let count = $w('#cargosTABLE').rows.length
 for (let i = 0; i < count; i++) {
 let rows = $w("#cargosTABLE").rows;
 let totali = Number(rows[i]["total"]);
 let pagoi = Number(rows[i]["pago"]);
 let fecha = rows[i]["fecha"];
 let tipo = rows[i]["tipoDePago"];
 let totalii = "" + fmt(totali)
 let pagoii = "" + fmt(pagoi)
        rows[i]["totalf"] = totalii;
        rows[i]["pagof"] = pagoii;

        $w("#cargosTABLE").rows = rows;
    }
}

Thanks in advance