The core idea to assign a thing (expense) more than one label (category) sounds very much like tags.
Example would be the label system in Gmail - where you can assign an email any combination of label.
You could make the totals add up if you dynamically create the unique categories from any existing combination of tags.
- Total of expenses that only have the label “insurance”
- Total of expenses that have the label “insurance” AND the label “car expenses”
- Total of expenses that only have the label “car expenses”
And only show a total line/ dynamic category if there are more than 0 expenses with that combination of labels.
So at the start, there is only 1 total line: “expenses without any label”,
As soon as the user assigns any label to an expense (let’s say “insurance”), then the new dynamic category appears.
Users cannot define dynamic categories. The dynamic categories would be generated from the label combinations assigned by the user to the expenses.
Visually, a tag UI would be intuitive for this. like: ￼
The amount of lines with subtotaal would depend on the labels the user assigns.
The subtotals would always add up.
The bad news:
There may be no subtotal for just insurance. if the user has some expenses with only “insurance” tag, and other expenses with both “insurance” and “car expenses” tags, there would be 2 subtotal lines.
This bad news may not be so bad: you could provide filters to always allow users to get a subtotal for “all expenses with labels xxx”.