Arron Bennett, Founder of Bennett Financials
That's one of my recent videos, on building a 13-week cash plan. One rule in it matters more than the rest. Put each payment in the week it will actually land in your bank account. Not the week it's due. And if a client is always late, put it late.
This post turns that rule into about 40 lines of pandas. You give it your paid invoice history. It tells you how late each client usually pays, and which week each open invoice should go in your forecast.
Full disclosure, I'm bad at math in my head. That's why I like a script for this.
Why not just use the due date?
Because the due date is what you asked for, not what happens.
Most cash forecasts drop every invoice in on its due date. Then the money doesn't arrive, payroll is tomorrow, and the forecast was wrong the whole time. Making a profit and having cash are not the same thing. An invoice is a sale. It isn't cash until it lands.
"Arron, my clients have 30-day terms. Isn't that the forecast?"
It's the forecast you'd like. It's not the one that happens. Terms are what's on the invoice. Behavior is what's in the bank.
Clients also pay in patterns. Some pay on the day. Some are always three weeks late because their accounts team runs payments once a month. Some are all over the place. Each of those needs a different forecast.
The data
This is a hypothetical example. The numbers are made up to show the method.
Let's say a 20-person IT managed services company bills four clients monthly. Here are three months of paid invoices: when each was sent, when it was due, and when the money landed.
import pandas as pd
# Hypothetical paid invoices for a 20-person IT managed services company.
paid = pd.DataFrame([
("Harbor Dental", "2026-06-01", "2026-07-01", "2026-07-02"),
("Harbor Dental", "2026-07-01", "2026-07-31", "2026-08-03"),
("Harbor Dental", "2026-08-01", "2026-08-31", "2026-08-31"),
("Pine Legal", "2026-06-01", "2026-07-01", "2026-07-24"),
("Pine Legal", "2026-07-01", "2026-07-31", "2026-08-21"),
("Pine Legal", "2026-08-01", "2026-08-31", "2026-09-25"),
("Metro Clinics", "2026-06-01", "2026-07-01", "2026-07-10"),
("Metro Clinics", "2026-07-01", "2026-07-31", "2026-09-14"),
("Metro Clinics", "2026-08-01", "2026-08-31", "2026-09-01"),
("Coastal Freight", "2026-06-01", "2026-07-01", "2026-07-29"),
("Coastal Freight", "2026-07-01", "2026-07-31", "2026-08-28"),
("Coastal Freight", "2026-08-01", "2026-08-31", "2026-09-30"),
], columns=["client", "sent", "due", "paid"])
for c in ["sent", "due", "paid"]:
paid[c] = pd.to_datetime(paid[c])
paid["days_late"] = (paid["paid"] - paid["due"]).dt.days
In real life you'd export this from your accounting system as a CSV and load it with pd.read_csv. Six to twelve months is better than three.
Profile each client
# Typical lateness per client, and how much it swings
profile = (paid.groupby("client")["days_late"]
.agg(typical="median", worst="max", spread="std")
.round(1)
.sort_values("typical", ascending=False))
print(profile, "\n")
The median is the typical delay. One wild month won't drag it around the way a mean would. The max is the worst case. The standard deviation tells you how predictable the client is.
typical worst spread
client
Coastal Freight 28.0 30 1.2
Pine Legal 23.0 25 2.0
Metro Clinics 9.0 45 23.4
Harbor Dental 1.0 3 1.5
Three very different stories. Harbor Dental pays on time. Pine Legal and Coastal Freight are steady-late: three to four weeks, every single time, which is usually a payment-run thing, not a problem client. Metro Clinics is the unpredictable one. Usually about a week late, but once it was 45 days.
Forecast the open invoices
Now take the invoices that haven't been paid yet and move each one to the week it should really land.
# Open invoices: forecast the week cash should land, using each client's typical lateness.
# Unpredictable clients (big spread) are forecast at their worst, not their typical.
open_inv = pd.DataFrame([
("Harbor Dental", "2026-12-31", 14000),
("Pine Legal", "2026-12-31", 22000),
("Metro Clinics", "2026-12-31", 18000),
("Coastal Freight", "2026-12-31", 9500),
], columns=["client", "due", "amount"])
open_inv["due"] = pd.to_datetime(open_inv["due"])
open_inv = open_inv.join(profile, on="client")
open_inv["lag"] = open_inv["typical"].where(open_inv["spread"] < 15, open_inv["worst"])
open_inv["expected"] = open_inv["due"] + pd.to_timedelta(open_inv["lag"], unit="D")
open_inv["week_of"] = open_inv["expected"].dt.to_period("W-SUN").dt.start_time.dt.date
print(open_inv[["client", "amount", "due", "lag", "week_of"]].to_string(index=False))
The where line is the important judgment call. Steady clients get their typical delay. Clients with a big spread get their worst delay. If they pay sooner, that's a nice surprise. If you forecast them at typical and they pay at worst, that's a payroll problem.
to_period("W-SUN") groups dates into weeks ending Sunday, so start_time gives you the Monday of the week the cash should land.
client amount due lag week_of
Harbor Dental 14000 2026-12-31 1.0 2026-12-28
Pine Legal 22000 2026-12-31 23.0 2027-01-18
Metro Clinics 18000 2026-12-31 45.0 2027-02-08
Coastal Freight 9500 2026-12-31 28.0 2027-01-25
All four invoices are due on the same day. Using the due date, your forecast would show 63,500 bucks landing in the week of December 28. Using real behavior, only 14 grand lands that week. The rest spreads across January and into February.
If payroll is in the first week of January, that's a very different picture.
What do you do with the late payers?
The script tells you who's late. It doesn't tell you why. That's a conversation, not code.
For steady-late clients like Pine Legal and Coastal Freight, the delay is usually built into how they pay. A monthly payment run. An approval step. A purchase order number that's missing from your invoice. Ask them what their accounts team needs, because a small fix on your side often pulls payment forward by two or three weeks.
For unpredictable ones like Metro Clinics, look at the bad month. Was it a disputed invoice? A new person in their accounts team? If it happens again, you might want a deposit or shorter billing cycles.
And look at your own side. If the gap between sent and due is long, you're adding days yourself. Billing at the end of the month for work done in the first week is a delay you fully control.
Why does this matter so much in a services business?
Because payroll doesn't wait. In a 20-person managed services company, staff get paid every two weeks, no matter when clients pay. So the timing of each payment decides whether a week is comfortable or tight.
Under the hood, this is the difference between a forecast you trust and one you ignore. A forecast built on due dates will be wrong in the same direction every month. After a while, nobody believes it. A forecast built on real behavior is close enough to act on.
That's when you call a slow payer early, push a purchase back a few weeks, or set up a line of credit before you need it.
The honest catch
A few things to watch.
- Small samples lie. Three invoices per client is thin. One odd month can move the median. Use as much history as you have.
- Behavior changes. A client who gets a new accounts team might speed up or slow down. Rerun this every month.
- The 15-day cutoff is a guess. Tune it to your business. The point is to be cautious with unpredictable clients.
- This forecasts timing, not risk of not paying at all. A client in trouble won't show up here until it's too late. Watch for sudden jumps.
Extending it
- Feed
week_ofandamountinto your weekly cash table with agroupby("week_of").sum(). - Add a "days from sent to paid" column too. If invoices go out late, that's a delay you control.
- Flag any client whose latest payment is far above their typical. That's often the first sign something's changed.
FAQ
Why median instead of mean?
The median isn't pulled around by one extreme month. For payment timing, that's usually what you want.
What about new clients with no history?
Use your terms plus a buffer for their industry, and lean late. Replace it with real data after a few invoices.
Should I chase steady-late clients?
Sometimes. Often the delay is a fixed payment run. Asking what their process needs, like a purchase order number, can pull it forward.
If you're curious about the business side, there's more in our accounts receivable research and on unbilled revenue in a service business.
Top comments (0)