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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Ahmed_Khalil
Frequent Visitor

Help to Manage Duplicate Values in Power Query at Power BI

i have the first column and i want a formula or any other way to return the value of Column B to be like below

ColumnAColumnB
10001000A
10001000B
10001000C
10001000D
10011001A
10011001B
10021002A
10031003A
2 ACCEPTED SOLUTIONS
tharunkumarRTK
Super User
Super User

  @Ahmed_Khalil

I have written the M-Code for your requirement. 

Screenshot 2024-08-03 at 12.53.24 PM.pngScreenshot 2024-08-03 at 12.51.33 PM.png

Please find the excel file and you will find the m code with in the query 'Table1'

 

 

Need a Power BI Consultation? Hire me on Upwork

 

Connect on LinkedIn

 




Did I answer your question? Mark my post as a solution!
If I helped you, click on the Thumbs Up to give Kudos.

Proud to be a Super User!

PBI_SuperUser_Rank@2x.png

 

 

View solution in original post

ronrsnfld
Super User
Super User

Given:

ronrsnfld_0-1722710043952.png

 

Using this M Code (which will reproduce the above table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFCK1SHEMMRgGMEYxkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t]),
    #"Grouped Rows" = Table.Group(Source, {"ColumnA"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "add Alpha", each List.FirstN({"A".."Z"},[Count]), type {text}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded add Alpha" = Table.ExpandListColumn(#"Removed Columns", "add Alpha"),
    #"Inserted Merged Column" = Table.AddColumn(#"Expanded add Alpha", "ColumnB", each Text.Combine({[ColumnA], [add Alpha]}, ""), type text),
    #"Removed Columns1" = Table.RemoveColumns(#"Inserted Merged Column",{"add Alpha"})
in
    #"Removed Columns1"

will return:

ronrsnfld_1-1722710134477.png

 

 

View solution in original post

4 REPLIES 4
ronrsnfld
Super User
Super User

Given:

ronrsnfld_0-1722710043952.png

 

Using this M Code (which will reproduce the above table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFCK1SHEMMRgGMEYxkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t]),
    #"Grouped Rows" = Table.Group(Source, {"ColumnA"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "add Alpha", each List.FirstN({"A".."Z"},[Count]), type {text}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded add Alpha" = Table.ExpandListColumn(#"Removed Columns", "add Alpha"),
    #"Inserted Merged Column" = Table.AddColumn(#"Expanded add Alpha", "ColumnB", each Text.Combine({[ColumnA], [add Alpha]}, ""), type text),
    #"Removed Columns1" = Table.RemoveColumns(#"Inserted Merged Column",{"add Alpha"})
in
    #"Removed Columns1"

will return:

ronrsnfld_1-1722710134477.png

 

 

ahadkarimi
Solution Specialist
Solution Specialist

Hi,
= Table.AddColumn(PreviousStepName, "ColumnB", each Text.From([ColumnA]) & Text.From([Index]))

sroy_16
Resolver II
Resolver II

Hello,

Please try using the m.language and see if it works or not.
A new custom column needs to be created and on it have this mcode.

Text.From([ColumnA]) & Text.From(Character.FromNumber(65 + ([Index] - 1) mod 26))

If you need more than 26 combinations (e.g., AA, AB), adjust the formula to handle multiple letters:

let
baseValue = Text.From([ColumnA]),
index = [Index] - 1,
firstLetter = Character.FromNumber(65 + Number.IntegerDivide(index, 26)),
secondLetter = Character.FromNumber(65 + Number.Mod(index, 26))
in
baseValue & firstLetter & secondLetter


Did I answer your question? Mark my post as a solution!
If I helped you, click on the Thumbs Up to give Kudos.

tharunkumarRTK
Super User
Super User

  @Ahmed_Khalil

I have written the M-Code for your requirement. 

Screenshot 2024-08-03 at 12.53.24 PM.pngScreenshot 2024-08-03 at 12.51.33 PM.png

Please find the excel file and you will find the m code with in the query 'Table1'

 

 

Need a Power BI Consultation? Hire me on Upwork

 

Connect on LinkedIn

 




Did I answer your question? Mark my post as a solution!
If I helped you, click on the Thumbs Up to give Kudos.

Proud to be a Super User!

PBI_SuperUser_Rank@2x.png

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors