Skip to content

Changing Data Types

Every column in Power Query has a data type, such as whole number, decimal number, date or text. Setting the types does more than format the data, because Power Query checks every value against its column’s type and flags any value that does not fit.

When a query is first created, Power Query usually adds a Changed Type step to Applied Steps on its own, with types guessed from the first rows of data. That step names each column it changes, so it is one more place where a renamed column can break the query. As a rule, the Changed Type step should:

  • appear only once in a query
  • come as late in the query as possible

It can be tempting to delete the step altogether, but that throws away the check. Setting types catches mistakes such as invalid dates and numbers typed in the wrong form, which are very hard to spot by any other means. The example below shows why.

A single row of monthly operating costs arrives like this:

An Excel row of Operating Costs with a column for each month-end date, values such as 1,250 and 3,205, a value of 54,50 under 30/04/2020 and a Total of 33,040

The source data

The row contains two mistakes:

  • November has only 30 days, so 31/11/2020 is not a valid date.
  • The April figure has been typed as 54,50.

Both are easy to miss, and Excel gives no clear warning about either. A typical manual check goes no further than selecting the Total cell and confirming that its formula covers the right range:

The same row with the Total cell selected, showing the formula =SUM(D4) and the summed range highlighted

Checking only the range of the Total formula

The range is right, but the total is not. Excel stores 54,50 as text, which SUM ignores, so the total of 33,040 leaves out 5,450 and understates the year’s operating costs by about 14%.

Running the same data through Power Query and setting the types brings both mistakes into view.

Load the table into the Power Query Editor:

The row in the Power Query Editor, with one column per date and 54,50 left-aligned as text under 30/04/2020 while the other values are right-aligned numbers

Select the Heading column, then choose Unpivot Other Columns, which turns the month columns into rows:

The unpivoted data with Heading, Attribute and Value columns, one row per month and a final Total row, where 54,50 is left-aligned in the Value column

The April figure already stands out, because it is aligned differently from the numbers around it.

Filter the Attribute column to remove the Total row:

The unpivoted data with the Total row filtered out, leaving twelve monthly rows and the step Filtered Rows in Applied Steps

Click the type icon at the left of each column header and choose a type from the list. Here Heading is text, Attribute is a date and Value is a decimal number:

The type menu open on the Attribute column, listing Decimal Number, Currency, Whole Number, Percentage, Date/Time, Date, Time and the other types, with Date highlighted

With the types set, the editor looks like this:

The typed data, where the 31/11/2020 row shows Error in the Attribute column and the April value now reads 5450

The invalid date now shows as an Error. The figure 54,50 has been converted to the number 5450, because the comma is read as a thousands separator. Had it been something that could not be read as a number, it would have shown as an error too.

Choose Close & Load to load the result to a worksheet:

The loaded Excel table of Heading, Attribute and Value, with 5,450 for April and a blank date beside the November value of 2,895

Add a total row to the table on the worksheet:

The same table with a Total row of 38,490

The total now includes April’s 5,450, and the blank date beside November’s figure makes it plain that something is wrong with that row.

Setting data types costs a few clicks and catches errors that a worksheet hides. Wherever the accuracy of the figures matters, keep the Changed Type step, and place it near the end of the query.