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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
o59393
Post Prodigy
Post Prodigy

transform a year into a date with power query editor

Hi all

 

I have a CSV with targets for different locations per year 2019 and 2020. To make it easier that csv contains only the column for year, since the target wont change per month.

 

How can I transform that single year column into a date with PBI's power query?

 

In other words go from 

 

targets.PNG

 

to 

 

targets2.PNG

 

thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

You could try this:   

Add a column to generate a list of month numbers:

= Table.AddColumn(#"Changed Type", "Month List", each List.Numbers (1, 12))

 

Choose "Expand to New Rows" to expand the list.

Annotation 2019-12-27 180745.jpg

Add a new column to combine the Year value with the month number value.  I used the "Column from Examples" feature with the Year and Month List columns selected.  Power Query inserted the following code:

= Table.AddColumn(#"Expanded Month List", "Month", each Text.Combine({Text.From([Month List], "en-US"), "/1/", Text.From([Year], "en-US")}), type text)

 

Finally, transform the Date column from text to date.  

Capture.JPG

View solution in original post

13 REPLIES 13
o59393
Post Prodigy
Post Prodigy

Hi all

 

I have a CSV with targets for different locations per year 2019 and 2020. To make it easier that csv contains only the column for year, since the target wont change per month.

 

How can I transform that single year column into a date with PBI's power query?

 

In other words go from 

 

targets.PNG

 

to 

 

targets2.PNG

 

thanks!

Duplicate post. Please don't do that. Causes confusion.



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

You use the #date() function, so #date([Year],1,1) will convert the integer in the [Year] field to Jan 1, 2019. But you didn't say how you expected it to do other days. You can put math in the month and day fields. The #date() function is identical to the DATE() function in Excel - #date(year,month,day)



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

 

I just need the first day of each month.

 

E.g.

1/1/2019

2/1/2019

3/1/2019  

 

and so on.

 

Still not sure how to make that transformation. I attach the pbix

 

https://www.mediafire.com/file/m63vzw5ms01icy0/QSE_model_test.pbix/file

 

Is the table called matriz_objetivos_bottler_2019 that contains the 2019 and 2020 value.

 

Thanks!

 

 

Anonymous
Not applicable

You could try this:   

Add a column to generate a list of month numbers:

= Table.AddColumn(#"Changed Type", "Month List", each List.Numbers (1, 12))

 

Choose "Expand to New Rows" to expand the list.

Annotation 2019-12-27 180745.jpg

Add a new column to combine the Year value with the month number value.  I used the "Column from Examples" feature with the Year and Month List columns selected.  Power Query inserted the following code:

= Table.AddColumn(#"Expanded Month List", "Month", each Text.Combine({Text.From([Month List], "en-US"), "/1/", Text.From([Year], "en-US")}), type text)

 

Finally, transform the Date column from text to date.  

Capture.JPG

Hi @Anonymous 

 

Appreciate the help! almost have it.

 

This is what I get when I use column from examples

target3.png

 

What should i do?

 

Thanks!

Anonymous
Not applicable

When you use "Column from Examples", you need to start typing in the outcome you expect, so that Power Query knows what you are trying to do.  In this case, type 1/1/2019, then in the next row type 2/1/2019.  It should pre-fill the rest of the rows of the new column.  

hi!

 

I did the formula to convert the year into dates, however I just noticed that is duplicating values.

 

year date.PNG

 

Went from

year1.PNG

 

Toyear2.PNG

 

 

year3.PNG

 

As seen the year 2019 appears 24 times, when it should be only 12 times.

 

How can I get it right?

 

Thanks!

Anonymous
Not applicable

Hi - In your screenshot of the Applied Steps, it looks like you are expanding the month list twice.  There is also a gear icon next to the first "Expanded Month List" which makes me think something else is going on with that step. 

 

The M code to expand the list should be:

= Table.ExpandListColumn(#"Added Custom1", "Month List")

 

Can you try deleting the last row of code in your query and check the code for the 5th row?

 

 Capture.JPG

Hi!

 

Still now working, at the moment I added the column with the formula 

 

Table.AddColumn(#"Changed Type", "Month List", each List.Numbers (1, 12))

 

I get this (step by step)

 

Column Month List added:

 

paso1.PNG

I go to the column added, unselect all and just click on month list

paso2.png

As seen below 4 rows appear, 2 for 2019 and 2 for 2020. Then I click on Expand New rows:

paso3.png

 

Once I click on expand rows I get this:

 

paso4.PNG

 

If I remove one of the steps added I get an error.

 

Can you share your pbix? Still dont know why is wrong.

 

Thanks!

Anonymous
Not applicable

Hi - check your code in the 4th step.  It should be:

 

=Table.AddColumn(#"Changed Type", "Month List", each List.Numbers (1,12))

It worked, thanks a mill 🙂

Don't use the column by example.

 

Use #date([Year],[Month.date.list.date.or.whatever.that.column.is.called],1)



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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors