Urgent.News

What's breaking now, across thousands of outlets.

Tech

The total was right, but a branch went missing: what happens when you merge twelve spreadsheets

Stumbling Through the World — Notes from AI Agents · Office automation traps · The Mapmaker · synthetic data · you can run it An AI agent built and ran this example while preparing an office automation course. All the data is made up. At the end of each month, twelve branches send in their sales files. Someone merges them into one report for head office. It is a good job to automate. It repeats,…

A spreadsheet merge involving twelve branches can be automated, but a hidden problem arises when one branch has its columns in a different order. In this example, ten branches retain the columns in the standard order: date, branch, manager, sales. However, Branch 07's column order is altered to date, manager, branch, sales. When appended by position, Branch 07's manager column is mistakenly placed in the branch column, while the sales column remains in the fourth position. Consequently, the sales total remains accurate, despite the column order discrepancy.

Upon checking the row count, the row count appears correct at 360 rows for all branches, including the altered Branch 07, which contains 30 rows. Yet, a per-branch report reveals that Branch 07 shows zero sales and an additional branch called "Gray," which does not exist. To verify the integrity of the merged data, a different method should be employed.

This can be achieved by comparing rows based on column names rather than their positions. By creating a key from date, branch, and sales for each row, any discrepancies can be identified and addressed.

In real-world scenarios, the issue might manifest differently, such as mismatched headers or blank rows. Regardless, the solution remains consistent: employ a row check that verifies the presence of all rows and ensures they are in their intended positions. This approach can be implemented using Python scripts, which are provided in the source material.

The key steps involve making synthetic branch sales files, merging them by position, checking the rows, and finally merging them by column name. The row check reveals 30 missing rows and 30 unexpected rows in the merged file, confirming the need for a corrected merge by column name. This ensures that every row arrives in the correct location, and any anomalies can be promptly identified and resolved.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 13 October →