Aggregate method

Question:
Please anyone can help me how to show result to my table1, or please any Idea to suggest. Thank you

Product:
async function leaveDetailsMonitoring() {
var entitledLeave = 14;
var result = 0;
const filter = wixData.filter().eq(“company”, “PRO-TRUCK”)
const filter2 = wixData.filter().eq(“leaveType”, “ANNUAL LEAVE”)
await wixData.aggregate(“LeaveDetails”).filter(filter && filter2)
.group(“fullName”)
.sum(“leaveApplied”, “leave_applied”)
.avg(“leaveApplied”, “counter”)
.run()
.then((res)=>{
result = entitledLeave - res.items[0].leaveApplied
$w(‘#table1’).rows = res.items
})

}

Additional information:

To display the results in your table:

  1. Combine Filters: First, use the .and() method to combine your filters (like company and leave type) to ensure you’re getting the right data.
  2. Calculate Remaining Leave: Once you get the data, calculate the remaining leave by subtracting the applied leave from the total entitled leave.
  3. Update the Table: Map the retrieved data to the table’s rows, making sure to include both the applied leave and the remaining leave for each person.
  4. Handle Errors: Add error handling to deal with cases where no data is found or if something goes wrong with the query.

If the problem still isn’t resolved, feel free to reach out, and we can set up a meeting to troubleshoot further.

Hi @Tech_Voyager
Thanks for your response, as I showed my code above, what want to do is to show to my table a result which is set it to a leave balance, but it doesn’t works. Is there any other way to calculate a balance beside using an aggregate method?

Hi Dennis,

You just want to show the cms data into table?

Hi @najmazahid

Thanks for response. what I want is to show a result of leave balance. which is leave applied is given. My problem is I can’t show leave balance in the table.

Have you connected the table and it’s elements to cms?
also what is type of “leave balance” field in the databse?

Hi @najmazahid

it doesn’t have leave balance in database, what only have is leave applied and leave entitled. Maybe can you suggest how to subtract leave entitled to leave applied? and result leave balance will create other new column

If using the aggregate method to calculate the leave balance doesn’t meet your needs, you can calculate the balance using custom logic by retrieving the data from your database collection and manipulating it with JavaScript.

hi @Tech_Voyager

Thanks for that information. This is the answer that clarified me. will you able to share with me of some idea on how to manipulating it? do I have to do that on a backend code?