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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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