Hello,
You could do that with a script and an automation, question being how you want to trigger this automation.
Here is what I tested:
Field "Test" here is just used to trigger the automation:
Script being (you will need to modifiy the table's name on first line, called "Items" in my example):
let table = base.getTable("Items"); // Replace with your table name
let query = await table.selectRecordsAsync();
let records = [...query.records]; // Create a mutable copy of the records array
// Sort records by "Timestamp" field in ascending order (earliest to latest)
records.sort((a, b) => {
let dateA = new Date(a.getCellValue("Timestamp"));
let dateB = new Date(b.getCellValue("Timestamp"));
return dateA - dateB;
});
// Loop through the sorted records to compute the "PointsTotal" field
let cumulativeTotal = 0;
for (let i = 0; i < records.length; i++) {
let pointsDelta = records[i].getCellValue("PointsDelta");
let newTotal;
if (i === 0) {
// For the first record, PointsTotal is just PointsDelta
newTotal = pointsDelta;
} else {
// For subsequent records, PointsTotal is PointsDelta + cumulativeTotal
newTotal = pointsDelta + cumulativeTotal;
}
// Update the cumulative total
cumulativeTotal = newTotal;
// Update the record with the new "PointsTotal" value
await table.updateRecordAsync(records[i].id, {
"PointsTotal": newTotal
});
}
Now, I guess that you want to compute this idependantly for each day. That's also possible, but it implies a more complex script or a different way to run and trigger the automation (with a "Find records action" on date for example)
Regards,
Pascal