cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kressb
Helper V
Helper V

Transforming Data by Year to 1st of each Month

I have data that is the same for the entire Calendar Year and comes like this:

kressb_0-1627320946623.png

I want to do a conversion via PowerQuery to have it like this (but for all 12 months):

kressb_1-1627320988090.png

I wanted to use "Expand to New Rows" but that isn't an option on the Calendar Year in Power Query.. Any ideas?

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@kressb try following steps in PQ:

 

- add a column for all the months, let's call it "Month"

 

{1..12}

 

- this will create a list column, expand the list so you will have 12 rows for each line.

- add another column, let's call it "Date" and we will build this "Date" column from Year and Month and give first day of the month.

 

#date([Year],[Month],1)

 

- and you can remove the columns you don't want and that will do it.

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





View solution in original post

3 REPLIES 3
viviank
Resolver I
Resolver I

This is a really interesting one, and I think I have a way to do it. First, you want to add a Month column in Power Query. Add a custom column, call it Month, and set the value to 1.

 

To get all 12 months, we need to duplicate this table 12 times! Make a duplicate of the table 12 times, and rename each table to the months. Call one January, one February, one March and so on.

 

Next, go to each of the 12 tables, right-click on Month, and choose Replace Values, and replace the value of the month so that it matches the month. For example, for March, change the 1 to 3. For November, change the 1 to 11. And so on.

 

Now --- Append all the 12 tables (January to December) to a new table. Now you have a table with rows for each month. All that is needed now is to get the MonthYr column done.

 

To get the MonthYr column, add a custom column. I used this formula:

= Table.AddColumn(Source, "MonthYr", each Date.From(#datetime([CalendarYear],[Month],1,1,1,1)))

 

This creates a date field, which you want, using the first day of each month. The other numbers don't matter, they are hours, minutes, seconds, which don't matter for dates, but you have to put something there, so I put in 1s.

parry2k
Super User
Super User

@kressb try following steps in PQ:

 

- add a column for all the months, let's call it "Month"

 

{1..12}

 

- this will create a list column, expand the list so you will have 12 rows for each line.

- add another column, let's call it "Date" and we will build this "Date" column from Year and Month and give first day of the month.

 

#date([Year],[Month],1)

 

- and you can remove the columns you don't want and that will do it.

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





@parry2k  perfect, thank you!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors