Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
Anonymous
Not applicable

convert number to date

Hi,

I have a date column I'm trying to import that is stored in the CSV file as numbers. I've tried converting the column to date but it doesn't recognise the date format I'm trying to use so it gives me all sorts of weird dates as a result. The dates are basically dd/mm/yy without the / seperator as below:

IDKFA_0-1594603834096.png

 

Any one know how I can transform this data into date data within power query? Do I need to make the changes after the data is loaded?

 

Thanks in advance.

 

Kind Regards,

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

please try to create a column

Column = 
VAR formatchange="0"&'Sheet24'[date]
VAR _newdate=if(LEN('Sheet24'[date])=5,formatchange,'Sheet24'[date])
VAR _day=LEFT(_newdate,2)
Var _month=mid(_newdate,3,2)
VAR _year="20"&RIGHT(_newdate,2)
return date(_year,_month,_day)

1.PNG

However, I fixed the year start from 2000, do you have any years before 2000? If so, then you need to modify the DAX.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

You can also just highlight your column in the query editor, and use the Column From Examples features.  You just type in the desired format (mm/dd/yyyy) and you will get a custom column auto created with a formula like this

 

=Text.Combine({Text.Reverse(Text.Middle(Text.Reverse(Text.From([Column1], "en-US")), 2, 1)), "/", Text.Reverse(Text.Middle(Text.Reverse(Text.From([Column1], "en-US")), 4)), "/", Text.End(Text.From([Column1], "en-US"), 2)})

 

Please see this link for a demo from Guy in a cube - https://www.youtube.com/watch?v=GUwtPIKtqO0

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@Anonymous , Try like

new Date=
var _1 = [Installationdate]& ""
var _2 =len(_1)
return
if(_2 =6 , date(year(right(_1,2)),year(mid(_1,3,2)),year(left(_1,2))),date(year(right(_1,2)),year(mid(_1,2,2)),year(left(_1,1))))
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
ryan_mayu
Super User
Super User

@Anonymous 

please try to create a column

Column = 
VAR formatchange="0"&'Sheet24'[date]
VAR _newdate=if(LEN('Sheet24'[date])=5,formatchange,'Sheet24'[date])
VAR _day=LEFT(_newdate,2)
Var _month=mid(_newdate,3,2)
VAR _year="20"&RIGHT(_newdate,2)
return date(_year,_month,_day)

1.PNG

However, I fixed the year start from 2000, do you have any years before 2000? If so, then you need to modify the DAX.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thank Ryan, this worked perfectly after I swapped in my column names!

Amit I didn't test your answer as Ryan's came in first sorry. Thank you for responding though! I'm sure I'll have another question for you this week 🙂

Kind Regards,

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.