Query table function sum not working

i have a block template to calculate tea expense.
-[[tea and snacks expense]]
amount::
expense-category::

I normally create blocks with this template in the journals page daily.

when I query with
{{query(and [[tea and snacks expense]] (between [[Mar 26th, 2023]] [[Apr 25th, 2023]] ))}}
it returns query table

and I use a query table function below it as a child block to the above query
{{function (sum :amount)}}
logseq does not return the total amount. what could be the reason?

It was working before, but now its not working.

2 Likes

Hi there,

I suggest hopping on this bug report in GitHub. Query table function `sum()` not work · Issue #9173 · logseq/logseq · GitHub

1 Like

This issue #9563 has not been fixed completely. I have been waiting patiently for the bug fix; but when I saw it was marked complete; I wondered whether it was intentional to partly fix it or was missed. I’m using the latest version and still facing the issue.

Although individual sum, average functions are working; this is not working:
{{ function (+(sum :x) (sum :y))}}

1 Like

Have you tried without a space between {{ and function ?

1 Like

yes, and didnt work.
It just shows a long string of concatenated numbers from the property values

1 Like

It works for me. If at least one of the values of the properties is a string itself instead of a number, it ends up like you said. Have you tried your query in a small dataset (preferably in a new graph), where you can quickly check each value?

2 Likes

Thanks @mentaloid for the clarification. My functions used to work earlier and stopped since 0.9.1 or so. I updated the empty fields to 0 and they gave a good result. Probably related to db structure changes.
Thanks again!!

1 Like

could you give me the query function to do that totalling of the costs i am also using it manage my expenses

1 Like

This used to happen to me often when my number formats were inconsistent. It has not happened in a while so it might have been fixed. If I have a block with qty:: 1.5, I will make sure I always have one digit after the decimal sign like qty:: 2.0 instead of qty:: 2 for example.

My OCD might be to blame because for all I know it is safe to override any scheme. :nerd_face: