Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RonB1985's avatar

Working with variable monthly prices

Not so much a coding issue but more like a general issue/question.

I am working on my budgetting app and I have a "Payment" model and an "Expense" model. To the payments, I can add monthly payments, such as Spotify, Netflix, etc. These are all fixed prices. So I can easily check if a montly payment was done by comparing the "Expense" amount against what the monthly payment should be.

But when adding variable amounts, such as Digital Ocean payments, these fluctuate and are not the same every month. My general question is, how would YOU fix this "issue"?

Some background: Right now on my "Payment" show view, I show all details of a payment. And there I also show if the payment has been done this month (by checking against the monthly expenses). Which is an easy task, when working with fixed prices such as rent, netflix, etc. But when it comes to payments that are not the same every month, what would be a good solution?

Something I came up with but I don't think is very good, is, when adding an expense for a particular payment, I update that payment amount to whatever the amount was for this last payment. But it feels a bit off to me, especially when I delete this last expense, to what will I update the payment amount?

So my general question is, which "logic would you use" to solve this problem? Any pointers?

0 likes
3 replies
vybeauregard's avatar
Level 54

You might consider marking certain Payments as variable, then take all of the ones to an individual payee and calculate the average amount. Once the charge comes in and you have an exact amount you can update the Expense as you are probably already doing.

If you have some months that are obviously outliers you could flag those to not be included in the average calculation, and perhaps apply a rolling 12-month average as you see fit.

It's a fuzzy approach (just like budgeting!), but probably a little better than assuming last month's amount will be an exact match.

3 likes
RonB1985's avatar

Thanks for the answers, after having read everything carefully, I think I came up with something that fits my case.

I will keep the "variable" option for a payment, which means I can select if a payment is a fixed amount every month or a variable amount. And instead of checking if the amount that was paid for the current month is the same as the amount that should be paid, I simply check if a payment was done this month, so it becomes irrelevant what the amount was, for the variable payments.

Thanks a lot for the replies and helping me get a solution for this!

3 likes

Please or to participate in this conversation.