Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
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.
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
69 | |
61 | |
18 | |
16 | |
13 |