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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
AlbertPietens
New Member

How to get unique column

Hello,

 

I need to make a unique column to get a 1-to-1 relation with another column. I have the table below:

 

Header
A
A
B
B

 

And the table I need is:

 

HeaderUnique
AA1
AA2
BB1
BB2
3 REPLIES 3
parry2k
Super User
Super User

@AlbertPietens start a new blank query, click advanced editor, and copy this code. You can follow these steps in your data.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YGRTjAyFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Header = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Header", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Header"}, {{"All", each Table.AddIndexColumn(_, "Rank", 1)}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Rank"}, {"Rank"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded All",{{"Rank", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Unique", each [Header] & [Rank], type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Rank"})
in
    #"Removed Columns"


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@AlbertPietens it will make more sense to do it in PQ, let me know if that is something you would like to do.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k Power query is fine. Ho should I get this using power query?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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