Forum Discussion
Convert Number to Date
- 8 years ago
Hi faruux6,
By my tests, you could change the data tyoe in Query Editor.
1. Go to Query Editor and change the column type from number to text, then change the text type to date.
You should note that when you have a remind, you should select the add a new step. Then you will get the data type.
2. Close && Apply. Go to Power BI Data view and click the column and change the data format of the column to 2001(YYYY).
Hope this can help you!
Best Regards,
Cherry
- Anonymous8 years ago
My recommendation is to do it explictally as part of the Edit Query. If you have a column that contains only a Year Value, create a new column (Add Column -> Custom Column) called "YearStartDate". The formula in the UI box should be:
= Date.FromText(Number.ToText([Year]) & "-01-01")
This will tell Power BI that you want a date value of that given year, as 1st January. From here you can format the data as type Date. Then use the formatting suggestion of v-piga-msft
If you do a direct conversion to date, it can get a weird result.
like 2017 (integer) to 1905 (yyyy)
- Anonymous6 years agoNot applicable
bjh497 thats because a date value is actually an integer that stands for "Days since 31/12/1899". By converting 2017 directly into a date, you have made the assumption that it would understand that 2017 is the year and not "days since"