March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
hey
So I have a following issue: I want to convert a column which includes numbers like "1995", "2000" and "2005" to date (YYYY). How can I do that.
thanks for your help
Solved! Go to Solution.
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
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
Very trivial but very useful. i almost got stuck and then realize power Bi can only indentify date in text but no date in numeric. great learning !!
Text To Date
=Date.FromText(Text.Range([Column1],0,4)&Text.Range([Column1],4,2)&Text.Range([Column1],6,2))
Number to Date
=Date.FromText(Text.Range(Number.ToText([Column1]),0,4) & (Text.Range(Number.ToText([Column1]),4,2)& (Text.Range(Number.ToText([Column1]),6,2))))
Thank you
If you do a direct conversion to date, it can get a weird result.
like 2017 (integer) to 1905 (yyyy)
@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"
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
Hi , I do have a yearmonth number column like 202202. How could I get a startdate column like 01/02/2022?
Thank you
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
114 | |
76 | |
57 | |
52 | |
44 |
User | Count |
---|---|
165 | |
116 | |
63 | |
57 | |
50 |