Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
You can do this via M but the results will be very surprising, and I am sure this is not what you actually need.
let
Source = {1..100},
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each Character.FromNumber(65+Int32.From(Number.Random()*26))),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Rows", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), type table [Column1=number, Custom=text, Index=Int64.Type]}}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Column1", "Index"}, {"Column1", "Index"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Rows",each [Custom],each if [Index]=0 then null else [Custom],Replacer.ReplaceValue,{"Custom"}),
#"Sorted Rows" = Table.Sort(#"Replaced Value",{{"Column1", Order.Ascending}}),
#"Removed Other Columns" = Table.SelectColumns(#"Sorted Rows",{"Custom"})
in
#"Removed Other Columns"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
Hi @Aasozab, check this:
You have to define column to replace here:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxU0lEyVIrVgTKNwMykJCDTGME0QTBNwczkZCDTDME0RzAtEExLpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
ColumnToReplace = "Column1",
GroupedRows = Table.Group(Source, {ColumnToReplace}, {{"All", each
[ a = Table.AddIndexColumn(_, "Index", 0, 1),
b = Table.ReplaceValue(a, each [Index] = 0, each null, (x,y,z)=> if y then z else x, {ColumnToReplace}),
c = Value.ReplaceType(b, Value.Type(a)),
d = Table.RemoveColumns(c, {"Index"})
][d], type table}}),
All = Table.Combine(GroupedRows[All])
in
All
Hi @Aasozab, check this:
You have to define column to replace here:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxU0lEyVIrVgTKNwMykJCDTGME0QTBNwczkZCDTDME0RzAtEExLpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
ColumnToReplace = "Column1",
GroupedRows = Table.Group(Source, {ColumnToReplace}, {{"All", each
[ a = Table.AddIndexColumn(_, "Index", 0, 1),
b = Table.ReplaceValue(a, each [Index] = 0, each null, (x,y,z)=> if y then z else x, {ColumnToReplace}),
c = Value.ReplaceType(b, Value.Type(a)),
d = Table.RemoveColumns(c, {"Index"})
][d], type table}}),
All = Table.Combine(GroupedRows[All])
in
All
why not delete row 147 too?
Actually, my question should be how to replace only the first occurrence of a value of a column? It doesn't matter to replace row 147 or row 169. Basic question is can we replace only first ocuurence or any number of occurrence of a value of a column using GUI options or M code?
You can do this via M but the results will be very surprising, and I am sure this is not what you actually need.
let
Source = {1..100},
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each Character.FromNumber(65+Int32.From(Number.Random()*26))),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Rows", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), type table [Column1=number, Custom=text, Index=Int64.Type]}}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Column1", "Index"}, {"Column1", "Index"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Rows",each [Custom],each if [Index]=0 then null else [Custom],Replacer.ReplaceValue,{"Custom"}),
#"Sorted Rows" = Table.Sort(#"Replaced Value",{{"Column1", Order.Ascending}}),
#"Removed Other Columns" = Table.SelectColumns(#"Sorted Rows",{"Custom"})
in
#"Removed Other Columns"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.