Forum Discussion
change date format
- 7 years ago
Hi admin_xlsior
In Edit queries,
1.click on your column Datekey, then select Add column->Date->Date only, thus get a column named "Date.1"
2.click on column "Date.1", then select Add column->Date->Year, thus get a column named "Year"
3.click on column "Date.1", then select Add column->Date->Month, thus get a column named "Month"
4.click on column "Month", then select Add column->Extract->length, thus get a column named "Length"
5.add a conditional column
6.select two columns and merge them,
click on "Custom" first, then keep the "ctrl" button pressed, click on another column "Month",
then select Add column->merge.
Then i get a new column "Merged"
7.finally, merge two columns "Year" and "Merged", you could remove other columns but keep useful columns.
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Pradeep,
Yes, actually I did the same, and my original column is Date/Time datatype.
So what I did is in Edit Query, Tab Add Column, new Customer column, and add this statement for formula = FORMAT([Datekey],"YYYYMM")
After I click ok, then Error : Expression.error The name 'FORMAT' wasn't recognized. Make sure it's spelled correctly.
On some resources, there is some statement saying Format is not available for Diret Query.
Thanks,
Hi admin_xlsior,
Don't go to Query Editor to do this.
We have Data page on the left side of your Power BI(Hghlighted in Yellow). Go to Data Page - > Find your DateKey Column and Right Click and Add "New Column". If will apply the format for your date. Use the same Expression given in previous post or see it in the DAX area.
Regards,
Pradeep
- admin_xlsior7 years agoPost Prodigy
Hi,
I'm using Direct Query, so no Data tab for that table.
Thanks.
- Anonymous7 years agoNot applicable
If you use DirectQuery, then you can add columns in SQL in the Advanced Options of Connection Establishment window.
In the SQL Statement Window, you can write SQL Query to add additional column to format of your date.
SELECT LEFT(CONVERT(varchar, GETDATE(),112),6)
Second, You can do it in Query Editor of adding two columns and merge together.
=Date.Year([DateKey]) // This would give you Year alone.
=Date.Month([Datekey]) // This would give you Month alone.
Select the above two created custom columns and Click on Merge Columns in the Transformation tab in Power BI.
Regards,
Pradeep