How to calculate net income in Obsidian Dataview?

Good day everyone! I am faced with my complete misunderstanding of how to calculate net income.

I use this code to calculate income

table
sum(rows.Income) as Income
from "Monthly"
where Income
group by true as Income

And the following code to calculate expenses:

table
sum(rows.Expense) as Expenses
from "Monthly"
where Expenses
group by true as Expenses

In my understanding, to calculate net income, you need to use:

table
some(non null(rows.Income))-sum(nonnull(rows.Expense)) as "Cash Flow"
from "Monthly"
where Income or Expenses
group by true as "Cash Flow"

But it doesn’t work and gives an error:
"Dataview: Every row during final data extraction failed with an error; first 3:

  • No implementation found for ‘number - string’"
    Although I’m sure there is no text there, I would appreciate any help

Does this fail?

```dataview
table
sum(nonnull(rows.Income))-sum(nonnull(rows.Expenses)) as "Cash Flow"
from "Monthly"
where Income or Expenses
group by true as "Cash Flow"
```

Yes, it did fail, but I was able to resolve the issue.

I am not sure why, but after using the “sum” command, the output was in text format, so I fixed it by converting the text to a number.

table
sum(nonnull(rows.Income))-number(sum(nonnull(rows.Expenses))) as "Cash Flow"
from "Monthly"
where Income or Expenses
group by true as "Cash Flow"

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