Forum Discussion

naveen73's avatar
naveen73
Helper III
4 years ago
Solved

extract year from

Hi all, I have a question on Power Query. I have a column that has some times dates in the right format e.g. 01/25/2025 and some times in the format e.g. Q3-2004. Is there a way I can write a code that will give me the correct year of the date for every entry?

 

Thanks,

 

Nav

  • Hello there naveen73 ! If I understood your situation correctly, I think this might give the result you are searching for:

     

    = Table.AddColumn(#"Your previous step", "Year", each if Text.Start([ColumnName],1) = "Q" then Date.StartOfQuarter(Text.Start([ColumnName],2)) else Text.End(Text.From([ColumnName], Culture.Current),4))

     

     If you keep the column formatted as a Date it should work as well!

     

    Hope this answer solves your problem! If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️ or give it a kudoe 👍
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Gonçalo Geraldes

10 Replies

  • Hello there naveen73 ! You have to select your date column in Power Query and use the "extract year" function as follows:

     

     And select Year -> Year and it will create a column with the year for every date.

     

    Hope this answer solves your problem! If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️ or give it a kudoe 👍
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Gonçalo Geraldes

     

  • goncalogeraldes thanks for your swift response.

    The cells with a value of "Q1-2002" give "null" with your proposed solution. I tried your solution in the first instance but did not work.