Start your 3-day free trial
Sign up to experience all premium features at no cost.
*Available only to new users. Each user is limited to one trial.


To clean messy spreadsheet data with AI, use the model to profile problems and propose explicit rules, then apply those rules with a deterministic tool to a copy of the data. Validate row counts, unique keys, missing values, data types, and control totals before accepting the result; never let a conversational answer silently rewrite the master workbook.
Key Takeaways:
- Freeze the source workbook and define the meaning of each field before cleaning it.
- Ask AI for candidate rules and exceptions, not an unexplained “clean” file.
- Run approved transformations with formulas, Power Query, OpenRefine, or code that can be repeated.
- Compare pre-clean and post-clean controls and keep rejected rows in an exception queue.
This workflow adds a data-quality loop to the general AI task method. It is intentionally separate from spreadsheet analysis: cleaning prepares trustworthy inputs; analysis interprets them.
Messy data is data whose representation makes its intended meaning ambiguous, inconsistent, or difficult to process. Typical problems include leading spaces, mixed date formats, numbers stored as text, inconsistent labels, merged cells, duplicate records, hidden error values, several facts in one column, and missing identifiers.
Not every difference is an error. ACME Ltd, Acme Limited, and ACME might be the same organization, three legal entities, or one company at different dates. A blank may mean unknown, not applicable, withheld, zero, or not yet collected. Cleaning begins with semantics, not with a global find-and-replace.
Create a data dictionary for every important field:
| Field | Business meaning | Expected type | Allowed values or format | Null meaning | Example |
|---|---|---|---|---|---|
| order_id | immutable order key | text | ORD- plus digits | never allowed | ORD-1042 |
| order_date | local transaction date | date | ISO YYYY-MM-DD | not recorded | 2026-08-04 |
| amount | gross amount | decimal | non-negative, currency separate | unknown | 1250.50 |
| status | current workflow state | category | pending, paid, canceled | not reviewed | paid |
The dictionary gives the AI something testable. Without it, the model may normalize values toward its own assumptions.
Work on a copy and preserve the original file read-only. Record the workbook name, sheet names, capture date, row count, column count, formulas, named ranges, hidden rows, and filters. Exporting a worksheet to CSV may discard formulas, formatting, comments, multiple sheets, and some type information, so record what the working format loses.
Profile each column with deterministic calculations:
Give the AI a schema, a small approved sample, and the profile rather than the entire sensitive workbook. Ask it to classify problems, propose rules, list assumptions, and identify values that require human decisions. Remove names, account details, private financial data, and identifiers that are not needed for rule design.
Use one row per proposed change:
| Field | Problem | Original | Target | Rule | Affected rows | Validation | Approver |
|---|---|---|---|---|---|---|---|
| status | case and spaces | Paid | paid | trim, then map approved labels | 184 | all values in allowed set | data owner |
| amount | decimal as text | 1,250.50 | 1250.50 | parse with declared locale | 72 | sum preserved | finance owner |
| customer_id | missing | blank | unchanged | send to exception queue | 11 | no invented IDs | steward |
This inventory is the contract between AI suggestions and execution. Reject any rule that cannot state its scope, exceptions, and validation.
Ask the model to reason from the data dictionary and profile. A useful prompt is:
Review this schema, profile, and redacted sample. List data-quality issues by field. For each issue, propose a deterministic rule, prerequisites, affected-value pattern, possible false positives, exception handling, and a validation check. Do not fill missing values, merge categories, delete rows, or infer identities unless an approved business rule explicitly allows it.
Request output in the problem-inventory columns. Then challenge the proposal with edge cases: accented names, non-breaking spaces, leading zeros in identifiers, dates such as 03/04/2026, negative adjustments, formulas returning empty strings, and duplicates whose latest row may not be authoritative.
AI is especially useful for drafting transformation expressions, test cases, and a review checklist. It is not the execution record. Copy approved expressions into a controlled query, formula set, or script and review them before running.
Low-risk normalization may include trimming known whitespace, applying an approved case convention to categories, or converting an unambiguous numeric string with a declared locale. Semantic decisions include merging customer identities, choosing a canonical address, imputing a missing value, or deciding which duplicate survives.
Put semantic decisions into an exception queue. A queue row should include the record ID, field, original value, candidate value, reason, evidence, owner, and disposition. The cleaned dataset must not hide unresolved items.
Choose an execution tool that records steps. Power Query is designed to shape data through an ordered query, and Excel lets you manage, duplicate, reference, merge, and refresh queries.[1] OpenRefine transformations apply expressions to cells and support previewing results and undoing operations.[4] Formulas or a script can also be appropriate when they are versioned and tested.
Apply the rules in a deliberate order:
Do not overwrite source cells in place. A query should read the frozen source and produce a new output, making it possible to refresh the same recipe when a new source file arrives.
Power Query's duplicate handling compares the columns you select.[2] Selecting too few columns can collapse different records; selecting every column can miss duplicates with trivial formatting differences. Define the key and record grain first.
Before removal, calculate duplicate groups and retain all members in an audit table. Decide whether records are exact duplicates, later corrections, separate events, or possible entity matches. If the business rule authorizes a survivor, record the ordering rule and preserve removed row IDs.
Power Query does not guarantee which duplicate instance it preserves.[2] That makes an explicit survivor rule and a retained audit table essential; the semantic decision still requires approval.
Excel's CLEAN removes the first 32 nonprinting characters in the 7-bit ASCII set, but Microsoft notes that it does not remove all additional Unicode nonprinting characters.[3] That limitation is a good example of why a familiar function must not be described as universal sanitization.
Combine text functions only under an explicit rule. Trimming ordinary spaces may not remove non-breaking spaces; changing case can alter case-sensitive identifiers; removing punctuation can corrupt reference codes. Test each transformation against representative and adversarial values.
Validation proves that the approved rules ran without damaging unrelated data. Compare controls before and after every material stage.
Use at least these checks:
| Control | Expected result |
|---|---|
| Source row count | unchanged until an approved filter or deduplication step |
| Output plus exceptions | equals the in-scope source population |
| Unique key count | matches the approved record-grain rule |
| Null count by field | changes only under an approved rule |
| Type failures | zero or present in the exception queue |
| Category distribution | only approved labels change |
| Numeric totals | preserved unless a documented correction explains the delta |
| Sample records | source-to-output values match the rule log |
Test idempotence: applying the cleanup recipe to its own output should not keep changing values. Then test refreshability with a fresh copy of the source structure. A recipe that works only once after manual cell edits is not reproducible.
Use control totals appropriate to the dataset: sum and count for transactions, counts by status for workflow records, minimum and maximum dates for events, and hashes or exact comparisons for fields that should never change. The validation report should distinguish pass, fail, and not applicable.
For high-impact data, have the data owner approve the rules and a separate reviewer inspect samples from changed, unchanged, and exception populations. NIST's AI risk guidance emphasizes information integrity and human oversight; a visible approval and evidence trail is safer than treating model fluency as quality assurance. Use the fact-checking guide for claims generated during the process.
Package the frozen source reference, data dictionary, profile, approved rule inventory, mapping tables, transformation recipe, exception table, validation report, and final output. Record tool versions and locale settings when they affect parsing.
A change log should state who approved each rule, when it changed, and why. If a source column changes meaning or type, stop the refresh rather than coercing it into the old schema. Schema drift is an input contract failure, not another value to “clean.”
Once the dataset passes quality controls, you can analyze the spreadsheet, visualize it responsibly, or compare it with another source using the two-spreadsheet reconciliation workflow.
In-place edits erase provenance and make recovery difficult. Read a frozen source and write a versioned output.
Duplicate appearance is not duplicate meaning. Establish record grain, group candidates, and approve a survivor rule before removal.
A plausible value is still invented. Preserve the null reason when known and route records requiring decisions to an exception queue.
03/04/2026 can mean different dates. Use a declared format, reject ambiguity, and retain the original value for review.
A cleaned file with no rule log cannot be reproduced or audited. Require deterministic steps and pre/post controls.
It can suggest and sometimes execute transformations, but automatic execution does not establish that the rules match your data's meaning. Review rules, run them on a copy, and validate the result before acceptance.
No. Some duplicates are separate events, corrections, or legitimate repeated values. Define the record key and business rule, review groups, and preserve an audit of any removed rows.
Only under an explicit, justified imputation rule with validation. Otherwise keep blanks, distinguish their meaning where possible, and route consequential missing values to review.
Declare the source locale and accepted formats, parse unambiguous values, and reject ambiguous dates into an exception queue. Keep the original string for audit.
It depends on the task. Power Query records ordered import and transformation steps; formulas can be transparent for smaller sheets. Either approach should preserve the source and support repeatable validation.
Calculate relevant control totals before and after, explain every authorized difference, and reconcile the output plus exceptions to the source population.
Prefer a schema, profiles, and a small redacted sample. Remove unnecessary identifiers and use only an approved service and account for the data classification.
Cleaning standardizes one dataset against its rules. Reconciliation compares two datasets, links corresponding records, and explains matched, unmatched, and conflicting values.
Sources:
Sources checked 30 August 2026.
Related articles:
Sign up to experience all premium features at no cost.
*Available only to new users. Each user is limited to one trial.