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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
meikastler
Frequent Visitor

Unstacking Forecast and Actual Data from a Single Column

I am brand new to Power Query and have been stuck on this problem for the past 5 days. I've tried watching tons of YouTube videos (especially by Goodly), but the solutions provided don't help my specific case. I feel that this is an extremely simple problem to fix, I just can't seem to make it happen. 

 

Attached in the picture, you'll find columns with Forecast and Actual, Months, and Quantities. 

 

5847e76f-f808-420c-9a55-987cbaff94c9.png

I'm trying to convert this into a list that looks like: 

Months / Forecast / Actual 

- the quantities are below the forecast and actual

 

How can I make this happen?

 

I really appreciate ANY help that I can get. 

 

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

No worries 🙂
OK, so if the values in column2 are unique for each value in column1, then a pivot-operation would do the job: 
1) Check Column1
2) go to Transform tab and choose "pivot column"
3) Select Column3 for the "Values Column"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

8 REPLIES 8
ImkeF
Super User
Super User

Good to see 🙂
The values in column1 are text values, so you need an additional helper column for the sorting.
Unfortunately - at least to my knowledge - there isn't a native function that derives the month number from a text string. So the formula is a bit more complicated.
Add a new column with the following formula

Date.Month(Date.FromText("2000-" & [Column1] & "-01"))

You can sort by it in the query editor.
But more importantly: You can use this column as the sort-by-column for your Column1 later in the data model.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

This was GOLD! Thank you so, so much! 😍

 

meikastler_0-1692991804199.png

 

ImkeF
Super User
Super User

No worries 🙂
OK, so if the values in column2 are unique for each value in column1, then a pivot-operation would do the job: 
1) Check Column1
2) go to Transform tab and choose "pivot column"
3) Select Column3 for the "Values Column"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

IT WORKED!!! OMG THANK YOU!!!

 

As a last question, how do I get the pivoted months to be in order?

 

meikastler_0-1692990818979.png

 

ImkeF
Super User
Super User

Hi @meikastler ,
that doesn't look to me like so.
In row 11 we have the 2nd jan and the column left to it shows "Forecast".

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

OMG! I did a Replace Values and the extra Jan is supposed to be November and the extra Feb is supposed to be December. I apologize! I took the photo before I fixed that particular error 😣

ImkeF
Super User
Super User

Hello @meikastler ,
What about the jan amounts in row 1 and 11: Should they be aggregated to 700 or kept separately?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

They need to be kept seperately. The first January is for the Forecast of a particular product quantity. The second January is for the Actual product quantity. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors