In my budget wiki, I have month, category and subcategory tiddlers with debit, credit fields.
credit field has <$list filter="[month<currentRecord>input_type[credit]get[amount]sum[]]"/>
debit field has <$list filter="[month<currentRecord>input_type[debit]get[amount]sum[]]"/>
Also there are input tiddlers with fields like amount, input_type, month, category, subcategory etc.
In the month tiddler, I want to show the percentage of expense under each category and subcategory for that particular month tiddler. How to do it ?
For example, consider the month tiddler May2022. All the petrol related tiddler in the month of May2022 will have the following fields
amount which will be manually filled.
category which will be Car
subcategory which will be Fuel
month which will be May2022
input_type which will be debit
Now in the May2022 tiddler I want to show the percentage expense in the category Car and subcategory Fuel for that month. Similar is the case for other categories and subcategories. How to do it ?
Thank you @amreus
I am getting some ideas after reading your code. Will test the code after making the changes need for my budget wiki and give back the feedback once I am back on my desktop.
I did a short testing and based on @amreus your suggestion and a previous suggestion by @Mark_S , I created two codes. Both needs to get mutliplied with 100 to get a percentage values. My attempts to add multiply operator didn’t work as expected. Any suggestions?
Edit: @amreus I forgot to study your second code showing the percentage. I will comment after trying it out.
One problem is you have no tiddlers which meet all the conditions of your filter. So there are no tiddlers with field month of “June2022” and category of “Car” and an amount that is not blank. Which means your variables are blank.
The demo does not have all the tiddlers (I have shared only a sample in the demo). The code is working in my personal wiki. I will update the demo later today since I am travelling currently.
fixed rounds to the given number of decimal places.
The fixed operator returns a string representation of the input number that does not use exponential notation and has exactly the specified number of digits after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length.