← Back to Blog
SQL & Python

From Manual Report to Scripted Report: A Simple SQL and Python Pattern

Shikha Kutariyar Lohani · 2 min read
SQL Python Automation

A monthly report that is rebuilt by hand every month is a good candidate for a script. The pattern below is simple and works for many finance reports.

1. Load and check the data

Read the source files or database tables. Before anything else, run checks: are there blank key fields, duplicate invoice numbers, dates outside the period, negative quantities? Stop and report problems instead of producing a report on bad data.

2. Query the numbers in SQL

Write the reporting logic once as SQL queries: sales by month, ageing buckets, top customers. SQL is clear about grouping and filtering, and the same query can be re-run next month.

3. Shape and chart in Python

Use Python to combine query results, calculate ratios and produce tables and charts. Keep the code in small named functions so each piece can be tested.

4. Reconcile and write the output

Compare the totals in the report with the source totals. Then write the output to an Excel or PDF file with a consistent layout.

5. Review before it goes out

A person reads the output, looks at the exceptions list and signs off. Automation should reduce typing, not remove responsibility.

A script you can re-run next month is worth more than a spreadsheet you cannot repeat.

Start with one report. When it runs reliably, apply the same pattern to the next one.

Shikha Kutariyar Lohani, Power BI Developer, SQL & Python Developer, Excel Developer and AI Architect. 7AM & Realtime CFO. Meet the team →

Want this built for your own data and process?

See Shikha’s services →

Have a quick question?

Leave your details — we reply within one business day.

No spam. Prefer WhatsApp? DM "DEMO" to +91-7011283542.

Know a founder who needs this? Send them a Fin-vite — that's how most conversations here start.