Operations & execution
Use ChatGPT to Merge Two CSV Files on a Shared Key Before Analysis
Summary
Cihan's view: Upload two structured CSVs with a common key, define the join type and variance rules before asking for a conclusion, then verify every merged row against both original files before sharing the final result with a finance owner for review.
A budget file and an actuals file often live in separate exports. ChatGPT can merge them on a shared identifier such as account, project, or month, but a clean join does not guarantee the comparison is correct. Define the merge rule and the variance logic first, then check every row before using the result.
This is a documentation-based tutorial with fictional data and an illustrative output. It is not a recorded ChatGPT session or a claim about financial accuracy.
Reader and decision
You are an operations manager preparing a monthly budget-versus-actuals review. Your artifact is a merged variance table that keeps every original row visible. Your decision is whether the merged file is ready for a finance owner, or whether the join or the rules need another pass.
The table should show the shared key, the budget amount, the actual amount, the variance, and any row that exists in only one file. It must not silently drop unmatched rows or invent values for missing data.
What you need
- ChatGPT with file upload and data analysis available for your account or workspace. Availability varies by model, plan, and settings.
- Two CSV files with a common key column (for example
account,project_id, ormonth). Use the fictional samples below while learning. - Permission to use the data in your approved AI environment.
OpenAI’s data analysis documentation says ChatGPT can analyze CSV files, create tables, and run Python-backed calculations. The extracting insights guide states that ChatGPT can merge multiple datasets together based on shared identifiers. It also recommends reviewing generated code, outputs, and assumptions before relying on a result.
1. Create the practice files
Save this as budget-sample.csv:
account,month,budget_amount
Acme Corp,Jan,50000
Acme Corp,Feb,50000
Acme Corp,Mar,50000
Beacon Ltd,Jan,30000
Beacon Ltd,Feb,30000
Beacon Ltd,Mar,30000
Cedar Inc,Jan,20000
Cedar Inc,Feb,20000
Cedar Inc,Mar,20000
Save this as actuals-sample.csv:
account,month,actual_amount
Acme Corp,Jan,47500
Acme Corp,Feb,51800
Acme Corp,Mar,50700
Beacon Ltd,Jan,30800
Beacon Ltd,Feb,29200
Beacon Ltd,Mar,30000
Cedar Inc,Jan,19500
Cedar Inc,Feb,20800
Cedar Inc,Mar,20300
Delta Co,Jan,15000
Delta Co,Feb,15000
Delta Co,Mar,15000
The files share account and month as a composite key. Delta Co appears only in actuals (a new customer). All other rows have matches in both files. The numbers are fictional.
2. Upload both files and set the merge rules
Start a new ChatGPT conversation, attach both budget-sample.csv and actuals-sample.csv, and use this prompt:
Analyze only the two attached files: budget-sample.csv and actuals-sample.csv.
First report: column names and row counts for each file, the shared key columns you detect, and any accounts or months that appear in only one file. Do not silently drop, rename, or fill any value.
Merge the files on the composite key (account, month) using a full outer join so every row from both files is preserved. For each merged row, calculate variance = actual_amount - budget_amount. When a value is missing in one file, show the variance as NOT CALCULATED and keep the row.
Return:
1. A merged review table with account, month, budget_amount, actual_amount, variance, and a match_status column (matched, budget_only, actuals_only).
2. A reconciliation: total rows in budget, total rows in actuals, matched rows, budget-only rows, actuals-only rows.
3. The Python code or calculation steps used for the merge and variance.
4. A short note saying whether the merged table is ready for human review.
Do not calculate percentages, running totals, forecasts, or business impact. Do not infer why a variance exists. Keep every row from both files visible.
The prompt defines the join type (full outer), the key, and the variance formula before the model writes a conclusion. If data analysis is unavailable, use a spreadsheet or another approved method with the same rules.
3. Review the expected merged table
For the fictional samples, an acceptable merged table should have 12 rows (9 matched + 3 actuals-only for Delta Co). The following is an illustrative target calculated from the samples, not captured ChatGPT output:
| account | month | budget_amount | actual_amount | variance | match_status |
|---|---|---|---|---|---|
| Acme Corp | Jan | 50000 | 47500 | -2500 | matched |
| Acme Corp | Feb | 50000 | 51800 | 1800 | matched |
| Acme Corp | Mar | 50000 | 50700 | 700 | matched |
| Beacon Ltd | Jan | 30000 | 30800 | 800 | matched |
| Beacon Ltd | Feb | 30000 | 29200 | -800 | matched |
| Beacon Ltd | Mar | 30000 | 30000 | 0 | matched |
| Cedar Inc | Jan | 20000 | 19500 | -500 | matched |
| Cedar Inc | Feb | 20000 | 20800 | 800 | matched |
| Cedar Inc | Mar | 20000 | 20300 | 300 | matched |
| Delta Co | Jan | NOT CALCULATED | 15000 | NOT CALCULATED | actuals_only |
| Delta Co | Feb | NOT CALCULATED | 15000 | NOT CALCULATED | actuals_only |
| Delta Co | Mar | NOT CALCULATED | 15000 | NOT CALCULATED | actuals_only |
Reconciliation:
- Budget rows: 9
- Actuals rows: 12
- Matched rows: 9
- Budget-only rows: 0
- Actuals-only rows: 3 (Delta Co Jan, Feb, Mar)
Variance arithmetic (independently checked):
- Acme Jan: 47500 - 50000 = -2500
- Acme Feb: 51800 - 50000 = 1800
- Acme Mar: 50700 - 50000 = 700
- Beacon Jan: 30800 - 30000 = 800
- Beacon Feb: 29200 - 30000 = -800
- Beacon Mar: 30000 - 30000 = 0
- Cedar Jan: 19500 - 20000 = -500
- Cedar Feb: 20800 - 20000 = 800
- Cedar Mar: 20300 - 20000 = 300
Check these figures before using the workflow with real data.
4. Apply the acceptance checks
The merge passes only when:
- Both files’ column names and row counts are reported correctly.
- The shared key is identified as the composite of
accountandmonth. - All 12 rows appear in the merged table (9 matched + 3 actuals-only).
- Delta Co rows show
budget_amountas NOT CALCULATED andmatch_statusasactuals_only. - Every matched row has a numeric variance equal to
actual_amount - budget_amount. - The reconciliation totals match the source file counts.
- The Python code or steps show a full outer join on the composite key.
- The note calls the table a review draft and does not present it as an approved financial statement.
If any check fails, fix the input files or clarify the prompt and rerun the merge. Do not share a polished variance table while unmatched rows or calculation rules are unresolved.
Troubleshooting decision guide
- Rows are missing from the output: ask for the row counts of each source and the match_status breakdown. A left or inner join may have been used instead of full outer.
- Delta Co rows show a numeric variance: restate that variance must be NOT CALCULATED when budget_amount is missing, and ask for the exact merge code.
- The key is detected as a single column: confirm the composite key (
account,month) and rerun. A single-column join onaccountwould duplicate months. - Column names differ (e.g.,
Accountvsaccount): ask ChatGPT to report the exact column names from each file, then standardize the key names in the prompt or the source files before merging. - The file is too large or complex: OpenAI notes that a file can be too large, complex, or poorly structured for complete analysis. Split into smaller approved files or ask for specific accounts or months.
Limits and safe use
A correct merge does not make the business conclusion correct. Review the join logic, the variance formula, the generated code, and the original exports. Do not upload confidential budget or actuals data unless your organization permits that exact environment and retention setting. Use a human finance owner for decisions involving payments, performance action, compliance, or customer commitments.
TRY this on fictional or approved samples to learn whether the join and variance definition are useful. SKIP uploading sensitive financial data without permission. USE the merged table only as a review queue after the source rows, join logic, and arithmetic pass inspection.