Help with dataviewjs query

if

dv.list(
	dv.pages('"TCPA/Cases"')
		.where(p => 
			p.payment_due
			)
		.payment_due
)

yelds

* 24457.85
* 1612.8
* 3000
* 3600

why does

dv.func.sum(
	dv.pages('"TCPA/Cases"')
		.where(p => 
			p.payment_due
			)
		.payment_due
)

return nothing

Most likely because you’re trying to sum texts…

The following is untested, but try something along the lines of:

```dataviewjs 
dv.func.sum(
	dv.pages('"TCPA/Cases"')
		.where(p => 
			p.payment_due
			)
		.map(p => parseFloat(payment_due))
)
```

no luck.

It seems I was a little tired when answering yesterday. A dataviewjs needs to have some sort of output function to present any result. In the first case you’re using dv.list(), but in the second one you don’t have anything, so the sum is actually calculated OK, but it’s never displayed.

```dataviewjs
const sum = dv.func.sum( 
  dv.pages('"ForumStuff/f77/f77973"')
    .where( p => p.payment_due )
    .payment_due
  )

dv.paragraph("Due payments: " + sum.toFixed(2))
```

This variant calculates the sum, and uses dv.paragraph to present a full block with the result. You could also use dv.span() for inline variants. I’ve also added a little bit of formatting just for the fun of it, and then we end up with:

image

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.