Forum Discussion
in PowerQueryEditor, Convert DateTime to YYYMM
- Anonymous4 years ago
Unfortunately, this leaves you with a text field. If you want it to be useable as a date:
From the Power Query Editor, add a new column as beginning of month:
Table.AddColumn(#"Filtered Rows", "dtStartOfMonth", each Date.StartOfMonth([dtRunDate]), type datetime)
From the Data View, format the date using yyyy-mm:
dtRunMonth = FORMAT(OLAPJobHistory[dtStartOfMonth],"yyyy-mm")
That makes sense, except I am having trouble with the addcolumn syntax. I stepped thru the "Custom Column" in the Power Query Editor and it built this, which throws an error:
= Table.AddColumn(dbo_OLAPJobHistory, "dtRunMonth", each DateTime.ToText(dbo_OLAPJobHistory[dtRunDate],"YYYYMM"))
What am I missing?
I'm not by a computer but I think your problem is power query doesn't want the table reference in front of the colum (that's dax syntax).
try
[dtRunDate] instead of dbo_OLAPJobHistory[dtRunDate]
- Anonymous4 years agoNot applicable
This worked for me:
= Table.AddColumn(dbo_OLAPJobHistory, "dtRunMonth", each DateTime.ToText([dtRunDate],"yyyyMM"))
Thank you
- bcdobbs4 years agoCommunity Champion
Missed that you said datetime in question. Glad it's working.
- Anonymous4 years agoNot applicable
Unfortunately, this leaves you with a text field. If you want it to be useable as a date:
From the Power Query Editor, add a new column as beginning of month:
Table.AddColumn(#"Filtered Rows", "dtStartOfMonth", each Date.StartOfMonth([dtRunDate]), type datetime)
From the Data View, format the date using yyyy-mm:
dtRunMonth = FORMAT(OLAPJobHistory[dtStartOfMonth],"yyyy-mm")