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
StefanoP
Regular Visitor

Merge Rows into one row parsing two columns

Hello there, hope this is not a redundant thread.

As in picture, I got a table where are stored users for certain applications and their roles.
It could be reaaally nice to have one row for every user that use that system and all the roles granted...on one row obviously.
I tried to make transpose transformations and pivoting columns found on some guides on the web, but it's related to one column.
Here I have two major columns to deal with ( System and Users ) and fill unkwon role ( because a user can have only one kind of grant for that system ) with null or NA ( whatever ).

So, this is an example of what I have

SYSTEMUSERROLE
sys1usr1role 1
sys1usr1role 2
sys1usr1role 3
sys1usr1role 4
sys1usr1role 5
sys1usr1role 6
sys1usr2role 1
sys2usr1role1


This is what I crave for

SYSTEMUSERROLE 1ROLE 2ROLE 3ROLE 4ROLE 5ROLE 6
sys1usr1role1role2role3role4role5role6
sys1usr2role 1nullnullnullnullnull
sys2usr1role1nullnullnullnullnull

 

I'm a bit of stuck...can someone give me help?

Bests

Stefano

7 REPLIES 7
ronrsnfld
Super User
Super User

 - Group by SYSTEM and USER

 - Aggregate into a List of Roles

 - Expand the list into new columns

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKq4sNlTSUSotLgJRRfk5qQqGSrE6WCWMcEkY45IwwSVhikvCDE3CCMNVRqg6gOKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SYSTEM = _t, USER = _t, ROLE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SYSTEM", type text}, {"USER", type text}, {"ROLE", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"SYSTEM", "USER"}, {
        {"Role Count", each Table.RowCount(_)},
        {"ROLE", each [ROLE]}}),
    
    #"Number of Roles" = List.Max(#"Grouped Rows"[Role Count]),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Role Count"}),
    #"Extracted Values" = Table.TransformColumns(#"Removed Columns", 
        {"ROLE", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
   
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "ROLE", 
        Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), #"Number of Roles")
in
    #"Split Column by Delimiter"

 

i don't get how to apply it sorry

Paste the code I provided into the Advanced Editor of Power Query (Transform).  If you don't know how to do that, go through some tutorials in Power BI and Power Query to find out.

 

I'm sorry I don't get it well.

What did you try?

What happened when you ran the code?

What went wrong?

BA_Pete
Super User
Super User

Hi Stefano,

 

This looks like an XY Problem waiting to happen.

What are actually trying to achieve overall, as you're moving the data away from the most efficient structure here.

Power Query isn't really designed to format your data how you want it to look, but rather to transform/aggregate it into an efficient dataset for formatting later in Excel or Power BI.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Well, I'm sorry for that.

Still, I don't know how to do it neither in powerbi, I'm trying to figure out how...

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
Top Kudoed Authors