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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors