Table of Contents
Power Query records data-cleaning steps so you can apply them again when the source changes. Four useful tasks are splitting combined fields, calculating date differences, isolating errors, and turning monthly columns into rows.
Open the data in Power Query
In desktop Excel, use Data > Get Data > From File > From Excel Workbook for another workbook. Select the relevant table or sheet in Navigator, then choose Transform Data. For a table in the current workbook, select a cell in it and use Data > From Table/Range.
Keep a copy of the source and check headers and data types before transforming. Import menus vary by Excel version and platform.
1. Split a combined ID and customer name

If a column contains an order ID followed by a hyphen and a customer name, select it and choose Split Column > By Delimiter on the Transform tab or its right-click menu.
- Choose the actual separator used in your data, such as a hyphen.
- If only the first hyphen separates the ID from the name, choose Left-most delimiter. Splitting at every occurrence could break hyphenated names.
- Keep the output as columns and confirm.
- Rename the new fields and trim surrounding spaces where needed.
Check several records, including exceptions. Keep IDs as text when leading zeros matter.
2. Calculate delivery days with an explicit formula
Set Order Date and Delivery Date to the Date type. For elapsed calendar days, subtract the order date from the delivery date.

Choose Add Column > Custom Column, name it Delivery Days, and enter:
Duration.Days([Delivery Date] - [Order Date])For example, an order on June 2 delivered on June 5 gives 3 days. This is elapsed calendar time, not a count of working days. Review negative results and missing dates rather than replacing them with a plausible-looking number. Date-time values require a separate decision about rounding or fractional days.
3. Inspect errors before removing them
Power Query has a direct way to isolate error rows: select the affected column, then use Home > Keep Rows > Keep Errors. Do this in a duplicate or reference query if you want an audit view without filtering the main output.
For a reusable error flag, add a Custom Column with:
try [Order Date]
This returns a record, not a Boolean. Expand the new column with its header's expand button and choose HasError. Filter that field to true to inspect the rows with errors.
You can alternatively create a direct Boolean flag with (try [Order Date])[HasError]. Investigate the error details and fix the source or transformation rule. Replacing every error with zero or deleting all affected rows can silently distort the report.
4. Unpivot monthly sales columns
A table with one State column and separate columns for each month is convenient to read but often awkward to aggregate.

- Select the identifier column, such as State. If there are several identifiers, select all of them.
- Right-click and choose Unpivot Other Columns.
- Rename Attribute to Month and Value to Sales.
- Set suitable data types and check the result.

Each remaining row now associates a state, month, and sales value. Use Unpivot Columns on explicitly selected month columns instead if the table also contains fields that should not become sales rows. Review how blanks are represented before comparing totals.
Load and refresh the result
Review Applied Steps, compare totals and sample records with the source, then choose Home > Close & Load. When the source changes, refresh the query and check for errors again. Renamed columns or a changed file layout can break a previously valid transformation.
For related spreadsheet work, see useful Excel features. Technical references: Microsoft's delimiter options, error-record handling, and date and duration calculations.

Reader Comments 0
Sign in with email or Google to join the discussion.