Forum Discussion
Anonymous
5 years agoNot applicable
Replace null values with unique values
Hi, I need to replace null values in a column with unique values that are some combination of text and a incrementing number (for example "Some code 1", "Some code 2"). Main problem that I have i...
- 5 years ago
Anonymous ,
Try this mcode:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs7PTVVIzk9JVTBUitWJVgITCEEjbILGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Column1"}), #"Grouped Rows" = Table.Group(#"Replaced Value", {"Column1"}, {{"Rows", each if _[Column1]{0} = null then Table.AddIndexColumn(_, "Index", 1,1) else _, type table}}), #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Rows"}), #"Expanded Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "Rows", {"Column1", "Index"}, {"Column1", "Index"}), #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Expanded Rows", {{"Index", type text}}, "pt-BR"),{"Column1", "Index"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged") in #"Merged Columns"Also, check the attached file.
camargos88
Community Champion
5 years agoAnonymous ,
Try this mcode:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs7PTVVIzk9JVTBUitWJVgITCEEjbILGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Column1"}),
#"Grouped Rows" = Table.Group(#"Replaced Value", {"Column1"}, {{"Rows", each if _[Column1]{0} = null then Table.AddIndexColumn(_, "Index", 1,1) else _, type table}}),
#"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Rows"}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "Rows", {"Column1", "Index"}, {"Column1", "Index"}),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Expanded Rows", {{"Index", type text}}, "pt-BR"),{"Column1", "Index"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
#"Merged Columns"
Also, check the attached file.