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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
adam_mac
Helper I
Helper I

Converting text year to date in Power Query

Hi, i am trying to convert column Academic year which has been stored as a text field to a date format. When i do this however it returns 13/07/1905. Any ideas how i can fix this so it shows e.g. 2020 but in date format? 

 

1.PNG2.PNG

1 ACCEPTED SOLUTION
edhans
Super User
Super User

@adam_mac your image shows the 2021 is an integer, and converting an integer to date will give you the erroneous results you show - because Power Query counts days like Excel, and July 13, 1905 is the 2021'st day since Dec 31, 1899.

 

You need to convert it to actual text first, then convert to date by adding a step, not hitting "replace current."

IntegerToDate.gif



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
edhans
Super User
Super User

Glad to help @adam_mac - one of those live and learn things on quirks of Power Query. 😁



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

@adam_mac your image shows the 2021 is an integer, and converting an integer to date will give you the erroneous results you show - because Power Query counts days like Excel, and July 13, 1905 is the 2021'st day since Dec 31, 1899.

 

You need to convert it to actual text first, then convert to date by adding a step, not hitting "replace current."

IntegerToDate.gif



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

hi @edhans , that worked great. Thank you very much! i have been stuck on that for embarassingly long! 

AlB
Super User
Super User

Hi @adam_mac 

Just change the type to date in PQ and you should get a date 01/01/2021. Then in the DAX table you can set the format to show only the year (2001 (yyyy)) while keeping the date type. See it all at work in the attached file.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors