Script: Average envelope expenditures

  • 1
  • Idea
  • Updated 3 weeks ago
  • (Edited)
Hi there,

So, I have noticed that I constantly overspend or underspend in some envelopes so I needed a way to know my average expenditures per month per envelope so that I can update the envelope value accordingly. You can get the totals from Spending vs Budget panel, but not the average.

So I have written myself a "script" the some of you might find useful.
As it is a script written in JavaScript, you will need to use DevTools on your browser (I developed and tested it on Chrome). To reach the developer tools on Chrone, just press F12 and select Console tab or go to View -> Developer -> JavaScript console.

!!! IT IS A BAD IDEA TO ENTER ANY KIND OF CODE THAT YOU DO NOT UNDERSTAND INTO CONSOLE !!!
!!! IT IS A BAD IDEA TO ENTER ANY KIND OF CODE THAT YOU DO NOT UNDERSTAND INTO CONSOLE !!!
!!! IT IS A BAD IDEA TO ENTER ANY KIND OF CODE THAT YOU DO NOT UNDERSTAND INTO CONSOLE !!!
For that reason, I hope someone from the dev team will go through it and "approve" it as safe to use.

So, go to Spending by Month, open the console and enter this:
Array.prototype.map.call(
document.querySelectorAll('#month-envelope-container tbody tr'),
row => {
const values = Array.prototype.map.call(
row.querySelectorAll('td:not(.fixed-first-col)'),
column => column.innerText
);
const sum = values.reduce((a, b) => parseFloat(a) + parseFloat(b))
const average = sum / values.length;
const columnElement = document.createElement("td");
const strongElement = document.createElement("strong");
const valueText = document.createTextNode(average.toFixed(2));
strongElement.appendChild(valueText);
columnElement.appendChild(strongElement);
row.appendChild(columnElement);
  }
)
What this script does is it takes each line, gets the values, sums them (even the zeros), divides by the month count (you can actually filter a larger set/longer period) and appends the average to the end of each row bolded.



Just refresh and the page will get back to normal.

Hope this helps,
int0x20
Photo of int0x20

int0x20

  • 1 Post
  • 0 Reply Likes
  • confident

Posted 3 weeks ago

  • 1
Photo of Alex Park

Alex Park, Official Rep

  • 266 Posts
  • 56 Reply Likes
Hi int0x20,

Thanks for sharing this neat little tool you've worked on with us and the community. We've reviewed what you've written and can confirm that you won't make any unwanted changes to your Goodbudget household or data by running this code in the console. We can't promise that we won't make changes in the future that will affect the values the code draws on and thus affect the resulting math, but for the present we can say that it looks good, looks cool, and is super neat!

Thanks for sharing!