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
acbg
Resolver III
Resolver III

Pivot multiple month columns

I have a dataset which comes across normalized with 3 different months under month column. 

 

This needs to be pivoted has columns in a table for users.

 

Issue is the 3 months changes. 

 

I cannot use matrix for end users as there are too many other columns needed.

 

I tried pivoting the  in Power Query but since the column names are different the reports fail. 

 

I tried pivoting the source and bring in the data and auto-renaming the columns using the actual month names in another table. Again this is failing here as its being seen as a new column.

 

Any one has another suggestion?

 

Thanks!

 

 

1 ACCEPTED SOLUTION

Hi @acbg,

 

Based on my test, you should rebulid your visual here. As I can reproduce your issue here. Or if you just add rows in your data source, then everything should go well.

 

22222.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @acbg,

 

I made a sample as below. We can Pivot the Month column based on the sales column.

 

2.PNGCapture.PNG

 

Here is the M code in power query for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s3PK8kwVNJRAuFEpVgdJCEjIE5CFTIG4mRUIRMgTkEIgTSZopoFEjJDNcsIamMyqpARqlnGUBsTUYVMUM0yxrTRGNNGY4TrYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Month = _t, sales = _t, users = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"sales", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Month]), "Month", "sales", List.Sum)
in
    #"Pivoted Column"

For more details, please check the pbix as attached. If it doesn't meet your requirement, kindly share you sample data to me.

 

https://www.dropbox.com/s/lx3zjix9gbf472i/Pivot%20multiple%20month%20columns.pbix?dl=0

 

Regards,

Frank

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @v-frfei-msft

 

Is it possible to achieve the table shown in the first image with a dataset similar to the table in the second image?

@v-frfei-msft

 

if we use the actual month name instead of Month 1 then it does not work.

 

For example: Instead of Month 1,Month 2, Month 3. Use Jan, Feb and Mar.

 

Then re-name the months as Apr, May, Jun. in the dataset and reimport it. M code works when we pivot it with new column names as Apr, May and Jun.

 

But the end graph/table in Power BI do not auto-recognize the change in column names from Jan, Feb and Mar to Apr,May, Jun.

 

It errors out as its unable to find Jan, Feb and Mar columns.

Hi @acbg,

 

Based on my test, you should rebulid your visual here. As I can reproduce your issue here. Or if you just add rows in your data source, then everything should go well.

 

22222.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

@v-frfei-msft Thank you for the response.

 

I was hoping there is another way of automatting it.

 

I have the months changing on a weekly basis and would like for it to be automatted instead of fixing it each week.

 

Since I can't find a automatted solution, I have went back to calling the months Month1, 2 and 3 instead of the actual names.

 

 

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.