Power Query, Data Validation and Repeatable Cleanup
Automating imports and cleaning with Power Query, and preventing bad input with data validation rules.
Intermediate · about 5 hours · difficulty 3/5
Learn first: Lookups: XLOOKUP, INDEX/MATCH and Friends
If you clean the same export every week by hand, you are doing a job Power Query should do. It records each transformation as a step, so next week you just click Refresh.
Power Query essentials
- Get Data from CSV, folders of files, databases or web pages.
- Common steps: remove columns, change types, split columns, trim, replace values, filter rows, fill down, unpivot.
- Merge queries (joins) and Append queries (stacking files with the same shape).
- Every step is written in the M language; you rarely need to write M by hand but reading it helps debug.
- The same engine powers Power BI, so skills transfer directly.
Data validation
When people type data into your sheets, stop mistakes at the door:
- Dropdown lists from a reference range.
- Numeric and date limits, custom formula rules.
- Input messages and error alerts that explain what is expected.
- Protect sheets so formulas cannot be overwritten.
Deduplication and checks
Use Remove Duplicates carefully (decide which columns define a duplicate), and add check cells: row counts, totals that should match the source, counts of blanks.
Pitfall: Power Query type detection guessing wrong (e.g. treating product codes like "00123" as numbers). Always review the Changed Type step. Move on when you can combine a folder of monthly CSV files into one clean table with a single refresh.
Key concepts
- Importing from files, folders, web
- Type changes, split, trim, replace
- Merge and Append queries
- Unpivot columns
- Reading M code
- Data validation rules and dropdowns
- Sheet protection
- Control totals and check cells
Mini project
Download 12 monthly files of a public dataset (e.g. UK Land Registry price paid or a city's monthly transit ridership), combine them via Power Query From Folder, clean types, and produce a refreshable pivot.
Check yourself
Why is Unpivot often the first step when a spreadsheet has one column per month?
Free resources
- Power Query documentation (Microsoft Learn)
- Excel help and learning (Microsoft)