You could try doing something like default(splits, 1) as divider where it would use splits if it has a value, and 1 in the other cases, this should allow you to do cost / divider to get your personal cost. After doing that, you should also be able to group the query and do a sum(rows.personalCost) to get the total sum of those. Does this make sense?
Another option related to summing up the totals has been posted in the thread below, where we add a row to the original table after summing up some columns. You’d need some tinkering related to selecting the correct field, and to adjust the new row with empty columns for you multi column table. In general you shouldn’t to know a lot of javascript though.
Not sure I’m following this one… could you explain what you mean by grouping the query? When I tried your example, I get the following error: “no implementation found for ‘array / array’”
Given (a most likely not working version of your query):
```dataview
TABLE WITHOUT ID
cost, divider, pCost
FROM #xmas
FLATTEN default(splits, 1) as divider
FLATTEN cost/divider as pCost
WHERE type = "gift" AND !date
One could add a GROUP BY statement and use the sum() function, like in:
```dataview
TABLE WITHOUT ID sum(rows.pCost)
FROM #xmas
FLATTEN default(splits, 1) as divider
FLATTEN cost/divider as pCost
WHERE type = "gift" AND !date
GROUP BY true
```
As we do the GROUP BY all contents are moved into the rows lists, but since our calculation was just one of the column definition, we need to move it into a FLATTEN for storage and grouping, and finally it allows us to do the sum as shown above.
You could possibly simplify the FLATTEN statements into FLATTEN cost/default(splits, 1) as pCost when I think about it.