Hi,
I am facing an issue where I want to sum price that is purchased by my patients for analysis.
Here is the situation:
I have a database called “purchasedAnalysis” and it contains three fields where all of them are referenced fields.
-
who - who purchased it.
Referenced field for a collection called: Customers -
purchasedProduct - the products purchased.
this contains the product price which I want to sum (The price field is Number )
Referenced field for a collection called: Products -
PurchaseNumber - info for each purchase made
Referenced field for a collection called: purchaseInfo
This is the code that I have:
export function sumButton_click(event) {
const filter = wixData.filter().contains(“who”,$w(‘#who_Id’).text).andwixData.filter().contains(“purchaseNumber”, $w(‘#purchaseNumber_Id’).text)
//I connect both IDs to texts using datasets - there is no problem with this
wixData.aggregate(“purchasedAnalysis”)
.filter(filter) //filter for who and purchaseNumber is used here
.sum(“purchasedProduct.price”)//here is the problem, is this a correct method to sum values from a referenced field? Using dot? I am unsure.
.run()
.then((results) => { //wixData aggregated results
let sum = results
// when I immediately connected this value to text did not work.
//I tried parseFloat did not work either
//In Wix API, regarding sum, it states that the outcome value of sum method is number so I thought it was unnecessary to use parseFloat
//Hence, I think the issue is the referenced field method I used (using dot as such: purchasedProduct.price)
$w(‘#sum’).text = sum
})
}
}
Really appreciate it If you can help me
Thanks in advance!