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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
vw_golf_mk3
Helper I
Helper I

Power Query Transformation

Hi peeps,

 

Can anyone please help in solving a little tranformation challenge that I am facing as shown below by using Power BI/Query?

DataTransformation.jpg

 Thanks,

 

 

3 ACCEPTED SOLUTIONS
Thejeswar
Super User
Super User

Try Using the following M-Query for this purpose

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpUitWBsJLgrGQwywguBmKlgFnGEFYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [id = _t, roi = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"roi", type text}}),
    Partition = Table.Group(#"Changed Type", {"id"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"roi", "Index"}, {"roi", "Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Partition", "Custom", each if [Index] = 1 then "roi1" else if [Index] = 2 then "roi2" else "roi3")
in
    #"Added Custom"

The Output is as shown below

roi.PNG

 

 

 

View solution in original post

Iamnvt
Continued Contributor
Continued Contributor

you can try the following as well.

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each "roi"),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"id", type text}, {"roi", type text}, {"Custom", type text}}),
    Group_index = Table.Group(#"Changed Type", {"id"}, {{"index", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded index" = Table.ExpandTableColumn(Group_index, "index", {"roi", "Custom", "Index"}, {"roi", "Custom", "Index.1"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded index",{{"roi", type text}, {"Custom", type text}, {"Index.1", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each [Custom]&[Index.1]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom", "Index.1"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom.1]), "Custom.1", "roi")
in
    #"Pivoted Column"

Br, T

View solution in original post

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @vw_golf_mk3,

 

Please refer to Iamnvt's solution which can be achieved easily by GUI.

 

Group data based on id column.

1.PNG

 

Then, make a little modification to the highlighted code. And expand the "all data" field.

2.PNG

 

Choose "Index" column then pivot table.

3.PNG

 

4.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @vw_golf_mk3,

 

Please refer to Iamnvt's solution which can be achieved easily by GUI.

 

Group data based on id column.

1.PNG

 

Then, make a little modification to the highlighted code. And expand the "all data" field.

2.PNG

 

Choose "Index" column then pivot table.

3.PNG

 

4.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thejeswar
Super User
Super User

Try Using the following M-Query for this purpose

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpUitWBsJLgrGQwywguBmKlgFnGEFYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [id = _t, roi = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"roi", type text}}),
    Partition = Table.Group(#"Changed Type", {"id"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"roi", "Index"}, {"roi", "Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Partition", "Custom", each if [Index] = 1 then "roi1" else if [Index] = 2 then "roi2" else "roi3")
in
    #"Added Custom"

The Output is as shown below

roi.PNG

 

 

 

@Thejeswar That's great.

 

Is it possible to achieve this via GUI (clicking)?

 

Cheers,

Iamnvt
Continued Contributor
Continued Contributor

you can try the following as well.

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each "roi"),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"id", type text}, {"roi", type text}, {"Custom", type text}}),
    Group_index = Table.Group(#"Changed Type", {"id"}, {{"index", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded index" = Table.ExpandTableColumn(Group_index, "index", {"roi", "Custom", "Index"}, {"roi", "Custom", "Index.1"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded index",{{"roi", type text}, {"Custom", type text}, {"Index.1", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each [Custom]&[Index.1]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom", "Index.1"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom.1]), "Custom.1", "roi")
in
    #"Pivoted Column"

Br, T

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.