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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Padagon
Frequent Visitor

Pass 1 column to many columns and asign values from a second column

 

Hi, I was wondering if someone could help me in Power BI to go from this table, 

 

NameCategoryValueAction
ABCBlueOKGo
ABCGreenMidpointGo
EFGBlueMidpointDone
EFGGreenNODone
GHJBlueOKLead
GHJGreenNOLead

 

In this situation the Name and the Action is duplicated but having different category and a value for each one. I need to transform the category into columns, and visualize the value for each category as values for Blue and Green new columns

 

To this:

 

NameBlueGreenAction
ABCOKMidpointGo
EFGMidpointNODone
GHJOKNOLead

 

What I need to do is to visualize the table like this last one, I don't want to group the Name and the Action columns like when using a Matrix.

 

Thank you.

2 ACCEPTED SOLUTIONS
danextian
Super User
Super User

Hi @Padagon 

 

This calls for grouping and pivoting in M. Try this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRcsopTQVS/t5Awj1fKVYHJuFelJqaB6R9M1MK8jPzShDyrm7uCI1I0i75ealICmAG+Pkjy7l7eKHZ6pOamIIkhaINIhcLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Category = _t, Value = _t, Action = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Category", type text}, {"Value", type text}, {"Action", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Action"}, {{"Group", each _, type table [Name=nullable text, Category=nullable text, Value=nullable text, Action=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Pivoted", each let t = [Group]
 in 
 
 Table.Pivot(t, List.Distinct(t[Category]), "Category", "Value")),
    #"Expanded Pivoted" = Table.ExpandTableColumn(#"Added Custom", "Pivoted", {"Name", "Blue", "Green"}, {"Name", "Blue", "Green"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Pivoted",{"Group"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Name", type text}, {"Blue", type text}, {"Green", type text}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"Name", "Blue", "Green", "Action"})
in
    #"Reordered Columns"

danextian_0-1718061197897.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

aduguid
Super User
Super User

I'd use the pivot column feature in Power Query. 
https://learn.microsoft.com/en-us/power-query/pivot-columns

 

First open Power Query and select the "Transform" tab. Then select the column you want to use as a header and click the "Pivot Column" button.

aduguid_1-1718145853245.png

 

Then dropdown the "Advanced" option and select the aggregate value.

aduguid_0-1718062167152.png

 

After that you'll see the pivoted table.

aduguid_1-1718062237106.png

View solution in original post

2 REPLIES 2
aduguid
Super User
Super User

I'd use the pivot column feature in Power Query. 
https://learn.microsoft.com/en-us/power-query/pivot-columns

 

First open Power Query and select the "Transform" tab. Then select the column you want to use as a header and click the "Pivot Column" button.

aduguid_1-1718145853245.png

 

Then dropdown the "Advanced" option and select the aggregate value.

aduguid_0-1718062167152.png

 

After that you'll see the pivoted table.

aduguid_1-1718062237106.png

danextian
Super User
Super User

Hi @Padagon 

 

This calls for grouping and pivoting in M. Try this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRcsopTQVS/t5Awj1fKVYHJuFelJqaB6R9M1MK8jPzShDyrm7uCI1I0i75ealICmAG+Pkjy7l7eKHZ6pOamIIkhaINIhcLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Category = _t, Value = _t, Action = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Category", type text}, {"Value", type text}, {"Action", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Action"}, {{"Group", each _, type table [Name=nullable text, Category=nullable text, Value=nullable text, Action=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Pivoted", each let t = [Group]
 in 
 
 Table.Pivot(t, List.Distinct(t[Category]), "Category", "Value")),
    #"Expanded Pivoted" = Table.ExpandTableColumn(#"Added Custom", "Pivoted", {"Name", "Blue", "Green"}, {"Name", "Blue", "Green"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Pivoted",{"Group"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Name", type text}, {"Blue", type text}, {"Green", type text}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"Name", "Blue", "Green", "Action"})
in
    #"Reordered Columns"

danextian_0-1718061197897.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors