Forum Discussion
Help with using Table.ReplaceValue on several row values under several different Columns
- 5 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJRSkxOTi0uzi/KTC0G8gzQRGJ1opWCIv2Boshknn4iWAaqQQGLJlRj8fHySnNylGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SubSegment = _t, Segment = _t, SubCategory = _t, Category = _t]), #"Replaced Value" = List.Accumulate( Table.ColumnNames(Source), Source, (s,c) => Table.ReplaceValue( s, null, null, (x,y,z) => if List.Contains({"", "0", "N/A", null, "null"}, Text.Trim(x), Comparer.OrdinalIgnoreCase) then "Not Set" else x, {c} ) ) in #"Replaced Value" - Anonymous5 years ago
Hi edhans
Thanks for the swift response and tips💪😎you are a powerbi champ!
Meanwhile I tried another workaround that worked, and I would like to hear your thoughts on it.
= Table.TransformColumns(#"Trimmed Text", {{"EAN Code", each if _ = "" then null else _}}, each if List.Contains({null, "", 0, "n/a"}, _) then "Not Set" else _)
Let me hear if this is a viable solution, although I can see it solved my problem with changing several different values under different columns to one value if found.
Ahhh... I didn't even think about using list.accumulate here...
Yep, I remember having read a blog, saying that recursion/List.Accumulate/List.Generate are only ways to loop in PQ. Seems too few choices; but not too bad at all, it's easy to make a decision.