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
AndreasKvis
New Member

Transform data: Transpose, Pivot, Unpivot or another idea?

Hi all,

 

I have the following SAP data:

AndreasKvis_0-1631393820299.png

As you can see, the 4 rows of data is very similar, except for the partner column. Therefore, it would like to transform and group the data into a solution similar to the following: 

AndreasKvis_1-1631394101217.png

 

Do you guys know wether this can be acheived through the Power Query?

Note: The data is only dummy data, and in the real dataset, i have mulitple notifactions with different numbers of partners (in the example above there is 4 partners, however, it can vary from 3-6 parterns.

 

In advance - thank you for your help

/Andreas

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Notification", Int64.Type}, {"Typ", type text}, {"Create On", type date}, {"Material", type text}, {"Partner", type text}}),
    Partition = Table.Group(#"Changed Type", {"Notification"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Typ", "Create On", "Material", "Partner", "Index"}, {"Typ", "Create On", "Material", "Partner", "Index"}),
    #"Added Prefix" = Table.TransformColumns(#"Expanded Partition", {{"Index", each "Partner " & Text.From(_, "en-IN"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Partner")
in
    #"Pivoted Column"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Notification", Int64.Type}, {"Typ", type text}, {"Create On", type date}, {"Material", type text}, {"Partner", type text}}),
    Partition = Table.Group(#"Changed Type", {"Notification"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Typ", "Create On", "Material", "Partner", "Index"}, {"Typ", "Create On", "Material", "Partner", "Index"}),
    #"Added Prefix" = Table.TransformColumns(#"Expanded Partition", {{"Index", each "Partner " & Text.From(_, "en-IN"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Partner")
in
    #"Pivoted Column"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
rodrigosan
Resolver III
Resolver III

Hello, for your case, wouldn't it be better to divide it into a fact and dimension table?
Below is the deal I made:

 

Based on the data I created two tables

Part_1.png

Then I created the relationship:

 

 

Part_2.png
I understand that this way your analyzes will be much easier.


If you want to download the example file I created, follow the link:
https://github.com/roolsant/SOSPowerBI/blob/main/Transform_Data.zip

I hope I helped you.

Rodrigo Santos
https://www.linkedin.com/in/rodrigosanpbi/

 

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.

Top Solution Authors