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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors