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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
joel-abad
Regular Visitor

Unpivot more than one group of columns

Hi Everyone!

 

I have an Excel file like this one imported to Power BI:

joelabad_1-1721383662347.png

And I want to unpivot the "Evidenced" and "Compliance" Columns, but keeping only one "Attribute" (Organization) column with 2 different "Values" (Evidenced and Compliance). It should look like this one:

joelabad_2-1721383672430.png

I tried different things, but I am not being able to find a solution to this. Thank you everyone for the help!

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @joel-abad, for future requests provide data in usable format not as a screenshot! (if you don't know how - read note below my post)

 

Result

dufoq3_0-1721389501643.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLLRyFCUpMz8jKTE3NgAq5lmSmpecmpKSABfUc4iSKeX6IQXJJYVIKhClkmVidayQhmbGRqMU4rQZpwWYshR7TVxkR4lhSbnfNzC3IyE/NK0NQhxEG2mqBYCPF1QFF+cmpxMW29a0qMdzFiEhcb0w58PJD9ZjSwHznIsbNBNpujJi98VqMHL3pQEwoClDSAFgAW+AMA4kIq5q5YAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, #"Safety Related" = _t, #"Security Related" = _t, #"RAM Related" = _t, #"Req_Object Type" = _t, #"Derived requirement" = _t, #"Org1 Evidenced" = _t, #"Org2 Evidenced" = _t, #"Org3 Evidenced" = _t, #"Overall Evidenced" = _t, #"Org1 Compliance" = _t, #"Org2 Compliance" = _t, #"Org3 Compliance" = _t, #"Overall Compliance" = _t]),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(Source, {"id", "Safety Related", "Security Related", "RAM Related", "Req_Object Type", "Derived requirement"}, "Attribute", "Value"),
    Ad_Organization = Table.AddColumn(UnpivotedOtherColumns, "Organization", each List.Accumulate({" Evidenced", " Compliance"}, [Attribute], (s,c)=> Text.BeforeDelimiter(s, c)), type text),
    Ad_Attribute2 = Table.AddColumn(Ad_Organization, "Attribute2", each Text.Trim(Text.AfterDelimiter([Attribute], [Organization])), type text),
    RemovedColumns = Table.RemoveColumns(Ad_Attribute2,{"Attribute"}),
    AddedSuffix = Table.TransformColumns(RemovedColumns, {{"Attribute2", each _ & " Status", type text}}),
    PivotedColumn = Table.Pivot(AddedSuffix, List.Distinct(AddedSuffix[Attribute2]), "Attribute2", "Value")
in
    PivotedColumn

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

5 REPLIES 5
dufoq3
Super User
Super User

Hi @joel-abad, for future requests provide data in usable format not as a screenshot! (if you don't know how - read note below my post)

 

Result

dufoq3_0-1721389501643.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLLRyFCUpMz8jKTE3NgAq5lmSmpecmpKSABfUc4iSKeX6IQXJJYVIKhClkmVidayQhmbGRqMU4rQZpwWYshR7TVxkR4lhSbnfNzC3IyE/NK0NQhxEG2mqBYCPF1QFF+cmpxMW29a0qMdzFiEhcb0w58PJD9ZjSwHznIsbNBNpujJi98VqMHL3pQEwoClDSAFgAW+AMA4kIq5q5YAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, #"Safety Related" = _t, #"Security Related" = _t, #"RAM Related" = _t, #"Req_Object Type" = _t, #"Derived requirement" = _t, #"Org1 Evidenced" = _t, #"Org2 Evidenced" = _t, #"Org3 Evidenced" = _t, #"Overall Evidenced" = _t, #"Org1 Compliance" = _t, #"Org2 Compliance" = _t, #"Org3 Compliance" = _t, #"Overall Compliance" = _t]),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(Source, {"id", "Safety Related", "Security Related", "RAM Related", "Req_Object Type", "Derived requirement"}, "Attribute", "Value"),
    Ad_Organization = Table.AddColumn(UnpivotedOtherColumns, "Organization", each List.Accumulate({" Evidenced", " Compliance"}, [Attribute], (s,c)=> Text.BeforeDelimiter(s, c)), type text),
    Ad_Attribute2 = Table.AddColumn(Ad_Organization, "Attribute2", each Text.Trim(Text.AfterDelimiter([Attribute], [Organization])), type text),
    RemovedColumns = Table.RemoveColumns(Ad_Attribute2,{"Attribute"}),
    AddedSuffix = Table.TransformColumns(RemovedColumns, {{"Attribute2", each _ & " Status", type text}}),
    PivotedColumn = Table.Pivot(AddedSuffix, List.Distinct(AddedSuffix[Attribute2]), "Attribute2", "Value")
in
    PivotedColumn

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi @dufoq3 OK! Sorry for that, I take note for the next time! Thank you very much for the solution, but I'd like to learn how to do it, like the steps to follow (if that's possible) instead copying and pasting a code. I'm not a programmer and I'm not very skilled in coding stuff. My apologies

Hi, each step (except Ad_Organization) was done via User Interface. If you want to also check List.Accumulate - Rick de Groot made great article here.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

I got it!! Thank you very much 🙂

You're welcome 😉


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors