Sub topic 3
Compare actual spending with a budget
Prerequisites
This chapter assumes you have categorized transaction records for at least one month, a monthly summary with totals by category, and basic percentage arithmetic. Variance here means the difference between actual and planned amounts.
Compare actual spending with a budget
A budget is a planned amount for each category. Variance is actual spending minus the budget. A positive variance means you overspent, and a negative variance means you underspent.
from decimal import Decimal
budget = {
"Groceries": Decimal("300.00"),
"Dining": Decimal("80.00"),
"Utilities": Decimal("120.00"),
}
actual = {
"Groceries": Decimal("342.15"),
"Dining": Decimal("61.30"),
"Utilities": Decimal("92.10"),
}
rows = []
for category, planned in budget.items():
spent = actual.get(category, Decimal("0"))
rows.append((category, planned, spent, spent - planned))
for category, planned, spent, variance in sorted(rows, key=lambda r: abs(r[3]), reverse=True):
status = "over" if variance > 0 else "under"
print(f"{category:<10} budget {planned:>8} actual {spent:>8} {status} by {abs(variance)}")Sorting by absolute variance puts the largest differences first, which tells you where to look.
Read trends across several months
One month can mislead. Compare the same category across three or more months. A category that is over budget every month needs a new budget or a behavior change. A single high month often points to an irregular cost.
Track variable or irregular income
Record each income deposit as its own transaction. For variable income, set a baseline: use the lowest recent month as the amount you can count on, and treat anything above it as a buffer. Irregular income, such as a bonus, should go to savings or debt first, not into the monthly budget.
Keep your financial data private
Store your records in an encrypted location, such as a password-protected spreadsheet or an app with two-factor login. Avoid sharing exported files by email. Remove account numbers from any file you share.
Build a weekly and monthly review routine
A short weekly check catches errors early. A monthly review covers the full comparison.
Exercise
Using the example data, which category has the largest absolute variance, and is it over or under budget?
Show answer
Groceries, with a variance of 42.15 over budget.