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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

List with duplicates to columns

Hi guys,

 

I've a very simple question, but I can't figure it out myself. I have a list with two columns with in the first one numbers with duplicate values and in the second column letters that belong to that number. I want to create a column for each of this letter.

Nr                  Letter

1                       A

2                       A

2                       B

3                       A

 

I want;

Nr               Column1   Column2    ....

1                       A

2                       A                B

3                       A

 

How can I achieve this in Power BI? Or Excel, that would do the trick to.

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

using this post of how to create a partition index, you can write this in the advanced editor of power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjJCYTmBWcYQsVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Nr = _t, Letter = _t]),
    
    Partition = Table.Group(Source, {"Nr"}, {{"Partition", each _, type table}}),

    AddedCustom = Table.AddColumn(Partition, "Custom", each Table.AddIndexColumn([Partition], "Index", 1,1)),

    RemovedColumns = Table.RemoveColumns(AddedCustom,{"Partition"}),

    ExpandedCustom = Table.ExpandTableColumn(RemovedColumns, "Custom", {"Letter", "Index"}, {"Letter", "Index"}),
    
    PivotedColumn = Table.Pivot(Table.TransformColumnTypes(ExpandedCustom, {{"Index", type text}}, "nb-NO"), List.Distinct(Table.TransformColumnTypes(ExpandedCustom, {{"Index", type text}}, "nb-NO")[Index]), "Index", "Letter")

in

    PivotedColumn

cheers,

S

View solution in original post

2 REPLIES 2
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

using this post of how to create a partition index, you can write this in the advanced editor of power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjJCYTmBWcYQsVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Nr = _t, Letter = _t]),
    
    Partition = Table.Group(Source, {"Nr"}, {{"Partition", each _, type table}}),

    AddedCustom = Table.AddColumn(Partition, "Custom", each Table.AddIndexColumn([Partition], "Index", 1,1)),

    RemovedColumns = Table.RemoveColumns(AddedCustom,{"Partition"}),

    ExpandedCustom = Table.ExpandTableColumn(RemovedColumns, "Custom", {"Letter", "Index"}, {"Letter", "Index"}),
    
    PivotedColumn = Table.Pivot(Table.TransformColumnTypes(ExpandedCustom, {{"Index", type text}}, "nb-NO"), List.Distinct(Table.TransformColumnTypes(ExpandedCustom, {{"Index", type text}}, "nb-NO")[Index]), "Index", "Letter")

in

    PivotedColumn

cheers,

S

Anonymous
Not applicable

Great solution! Easy to use and works perfectly.

Much better than the Excel solutions.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.