How do i calculate sumtotal of a table in a dynamic page?

I have a dynamic page and I would like to show sum total of a specific row on a input1 (or text box).
When i use the following code it gives me the sumtotal of the specific row but for the whole database not filtered. Your help with be greatly appreciated. Thank you.



import wixData from 'wix-data';

$w.onReady(() => {
    Sum_amount();
});

export function Sum_amount(){
  wixData.aggregate("INCOME-EXPENDITURE")
  .sum("income","sumamount")
  .run()
  .then( (results) => {
      $w('#input1').value = results.items[0].sumamount;
  } );
}

  wixData.aggregate("INCOME-EXPENDITURE")
  .sum("expenditure","sumamount")
  .run()
  .then( (results) => {
      $w('#input2').value = results.items[0].sumamount;
  } );

When i use the following code it gives me the sumtotal of the specific row but for the whole database not filtered
So if it is not filtered, why you do not use a filter?

wixData.aggregate("INCOME-EXPENDITURE")
  .sum("income","sumamount")
  .run()
  .eq("COLUMN","VALUE")

Does it not work for you ?

Thank you for the reply but I’m failing to use the filter. The page is a dynamic page and I would like the code to filter according to the dynamic item so that the subtotal is not for the whole database column.