Accountants.
Their unit of work seems to be the month, as if individual days don't exists, or don't count somehow. Nowhere is this better seen than in the notion of the accounting period, which all too often follows the form YYYYMM. Try converting this directly into a date and Power Query starts making excuses faster than a kid with his hand caught in the cookie jar.
The quick solution to this is to understand what Power Query's Table.TransformColumns does, and then leverage this knowledge to transform your YYYYMM values into proper date type columns.
Table.TransformColumns
As it's name suggests, this handy function allows you to convert the contents of a column from one type to another. The basic syntax is:= Table.TransformColumns(Lists {denoted by curly braces} are something you need to get comfortable with if you want to harness the under-the-hood power of the M language. The example below lists two tuples - for ReportedDate and LossDate respectively. On both columns, the function Date.From is invoked, which attempts to convert in input value to a date type.
#"Your Source Table",
{ A list of tuples, specifying the columns and what functions to apply to each value} )
= Table.TransformColumns( #"Your Source Table",{This works fine for normal dates, but for YYYYMM dates we need to cook up our own function:
{"ReportedDate", Date.From}, {"LossDate", Date.From} })
= Table.TransformColumns(#"Replaced Value",{The secret here is in understanding what each does.
{ "Date",
each Date.From(Text.From(_) & "01") }})
It is shorthand for creating a nameless (or anonymous) function, where the underscore character represents the single parameter/argument being passed in by the caller.
The example above effectively says: "For each value in the Date column, convert the value to text (Text.From) then concatenate the string 01 (to create a text value of the form YYYYMM01) , then convert that text to a date type (Date.From) and put the result back into the Date column."
Give it a try!
Comments
Trying your custom function but in vain
File: filename.csv.bz2 (bz2 format)
Content: filename.csv (# separator)
Please help. I'm really new to the M language
I'm brazilian. I can't read, speak, or write in English, but I'm always learning from your tips. To write this text I used the translator.
I don't use Power BI either. I use Excel Power Query.
I need to import several .XML files, which are inside .FRE files, which are inside zipped folders. I could not import the .xml files without unzipping. An example of the file is available at https://github.com/msperlin/GetDFPData/raw/master/inst/extdata/FRE_6629_HERC_2010-12-31.zip
Thank you very much