I'm trying to sum up a data field from one query result. I have a database with title year/season(text) and the field I try to sum up is of type Number. I do this calculation inside of myDataBase_afterQuery(item, context), here is the code:
var itemDate1 = String(item.title); // 2014/2 var itemYear1 = itemDate1.split("/")[0]; // 2014 year var itemSeason1 = itemDate1.split("/")[1]; // 2 season wixData.query("SeasonData").startsWith("title", itemYear1) .eq("depart", item.depart).find().then( (results)=>{ // for each row entry, find the entries if(results.totalCount > 0){ // with the same year and same var i = 0; // department, sum the field var sum = 0; // salesAll let items = results.items; for(i = 0; i < results.totalCount; i++){ sum+=items[i].salesAll; } item.salesYear = sum; } }). catch((err) => { item.salesYear = err.message; });
My issue is, after I run the code the database gives me the correct sum for some rows but not all rows. Many rows are missing values and they are just blank. And occasionally I got database load errors: it loads successfully halftimes and fails the other half. Can someone please help me? Any suggestions would be appreciated.
![](https://static.wixstatic.com/media/a27d24_5a3a9188bf6140eba163bd3cf2a2962a~mv2_d_1920_1224_s_2.png/v1/fill/w_980,h_625,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/a27d24_5a3a9188bf6140eba163bd3cf2a2962a~mv2_d_1920_1224_s_2.png)
Anyone pls?