Forum Discussion

o59393's avatar
o59393
Icon for Post Prodigy rankPost Prodigy
6 years ago
Solved

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 ...
  • Anonymous's avatar
    Anonymous
    6 years ago

    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.

    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.