What I’m trying to do
I want to display certain values with dataview and have them summed up automatically. Also I want to display the subtotals for each column under the column before having the complete total for all the columns.
This mostly works, with the exeption of the placement of the subtotals:
As you can see, they are all under the “amount” column. This doesn’t really affect the functionality, but it would be much more pleasing to have the subtotals displayed under their coresponding columns.
This is the code for the current result:
```dataviewjs
const amounts = await dv.query(`
TABLE WITHOUT ID
file.link as "files",
amount, amount2, amount3
FROM #source
`)
if ( amounts.successful ) {
const sum = amounts.value.values
.reduce((tmp, curr) => tmp + curr[1], 0)
const sum2 = amounts.value.values
.reduce((tmp,curr) => tmp + curr[2], 0)
const sum3 = amounts.value.values
.reduce((tmp,curr) => tmp + curr[3], 0)
amounts.value.values.push(["<span style='float: right'><strong>Total:</strong></span>", sum])
amounts.value.values.push(["<span style='float: right'><strong>Total:</strong></span>", sum2])
amounts.value.values.push(["<span style='float: right'><strong>Total:</strong></span>", sum3])
dv.table(amounts.value.headers, amounts.value.values)
dv.paragraph("Total amount: " + (sum + sum2 + sum3))
} else
dv.paragraph("~~~~\n" + amounts.error + "\n~~~~")
```
Things I have tried
The code I currently have was already achieved with the help of some people here on Obsidian Forum. But I still never figured out this visual problem.
If anyone knows how to to this, the help would be greatly appreciated!