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
paybacksilver
Frequent Visitor

Replacing specific duplicate values in a column

Hello,

 

I was looking for a formula in PowerQuery that would replace a list of duplicate values until it hit a value that was not a duplicate, and apply this formula to the entire column. 

Thanks for any help!

 

Original -> Goal

11
1null
1null
44
4null
55
5null
5null
5null
5null
5null
5null
5null
77
7null
88
99
9null
1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Insert an Index column and use following formula where Data is your original column

= try if #"Added Index"[Data]{[Index]-1}=[Data] then null else [Data] otherwise [Data]

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1UElTZBIUxJJcyTSAkxawshYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Result", each try if #"Added Index"[Data]{[Index]-1}=[Data] then null else [Data] otherwise [Data]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Data", "Index"})
in
    #"Removed Columns"

 

 

View solution in original post

1 REPLY 1
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Insert an Index column and use following formula where Data is your original column

= try if #"Added Index"[Data]{[Index]-1}=[Data] then null else [Data] otherwise [Data]

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1UElTZBIUxJJcyTSAkxawshYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Result", each try if #"Added Index"[Data]{[Index]-1}=[Data] then null else [Data] otherwise [Data]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Data", "Index"})
in
    #"Removed Columns"

 

 

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