Power Query has quickly become my favorite data transformation tool because of its fluid, interactive approach to describing data transformation. It isn't just easier to use that traditional ETL tools, it's also significantly more powerful and is a lot more forgiving. Perhaps too forgiving...
Recently I worked on a solution for processing disparate spreadsheets that we receive from our partners. In theory it's simple enough: Combine the data tables, clean up the data, spit out the result.
The problem came in when we did checked the resulting data, and discovered that the monetary totals were way out of whack, and Power Query didn't report any errors in the data it had processed.
Consider the M query below, that imports the source data from a spreadsheet - take a close look at the ClaimAmount and VATOnClaimAmount columns. See anything wrong?
At first, the values appear to be normal monetary values, but on closer inspection we see that the value 131.58 is actually 131.58000000000001. In excel this would amount to nothing more than a harmless rounding error, but in Power Query this can cause undesired results. Notice the type hint at the left side of the ClaimAmount column heading - it shows that Power Query is treating the column as the any type.
The problem comes in when you transform the columns to the decimal number type. Depending on locale settings, the value may be interpreted in any of the following ways:
- Period denotes a decimal place.
The resulting value is what we expected. Yay.
or - Period denotes a thousands separator.
The resulting value is in the trillions.
Thankfully, the solution is fairly simple: Specify a locale during column conversion operations.
The column transform operation that the Power Query GUI creates for you will look something like this:
= Table.TransformColumnTypes(Source,{.. all you need to do is type in the locale at the tail of the TransformColumnTypes column:
{"ClaimAmount", type number}, {"VATOnClaimAmount", type number}
})
= Table.TransformColumnTypes(Source,{... and voila! Conversions treat the period as a decimal point, not a thousands separator.
{"ClaimAmount", type number}, {"VATOnClaimAmount", type number} }, "en-US")
Comments