Forum Discussion
Anonymous
6 years agoNot applicable
Replace multiple values in the same column in one step
Hello everybody, I am looking to a solution to replace several values in a column, in a single step, to have something like this: for now, here is what my query looks like: let Sourc...
- 6 years ago
Hi Anonymous ,
Here I created a sample for your reference.M code for your reference.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslMzyxJzFFwzUstSq9UCClKzCtOTC7JzM9LzFGK1YlW8sjPTVVIzEtRcMksLinKTCoFyYFlfPLLFcLyc0oS01Ox6Av1cwwO9nT3c3WBcoMDXJ093TxB/FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Current Value" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Current Value", type text}}), #"AllReplace" = [#"Digital Energy Transactional" = "BMP", #"Home and Distribution" = "BMP", #"Low Voltage Transactional" = "BMP",#"UNASSIGNED" = "BMP",#"UNSPECIFIED" = "BMP"], #"Replaced Value" = Table.TransformColumns(#"Changed Type",{{"Current Value",each Record.FieldOrDefault(AllReplace,_,_)}}) in #"Replaced Value"BTW, Pbix as attached.
v-frfei-msft
6 years agoCommunity Support
Hi Anonymous ,
Here I created a sample for your reference.M code for your reference.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslMzyxJzFFwzUstSq9UCClKzCtOTC7JzM9LzFGK1YlW8sjPTVVIzEtRcMksLinKTCoFyYFlfPLLFcLyc0oS01Ox6Av1cwwO9nT3c3WBcoMDXJ093TxB/FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Current Value" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Current Value", type text}}),
#"AllReplace" = [#"Digital Energy Transactional" = "BMP", #"Home and Distribution" = "BMP", #"Low Voltage Transactional" = "BMP",#"UNASSIGNED" = "BMP",#"UNSPECIFIED" = "BMP"],
#"Replaced Value" = Table.TransformColumns(#"Changed Type",{{"Current Value",each Record.FieldOrDefault(AllReplace,_,_)}})
in
#"Replaced Value"
BTW, Pbix as attached.
AnkitBI
6 years agoSolution Sage
Below is how I was able to achieve it
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslMzyxJzFFwzUstSq9UCClKzCtOTC7JzM9LzFGK1YlW8sjPTVVIzEtRcMksLinKTCoFyYFlfPLLFcLyc0oS01Ox6Av1cwwO9nT3c3WBcoMDXJ093Tyh/MSkZKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Current Value" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Current Value", type text}}),
Custom1 = Text.Combine({"Digital Energy Transactional","Home and Distribution","Low Voltage Transactional","UNASSIGNED","UNSPECIFIED"},","),
Custom2 = Table.TransformColumns(#"Changed Type",{{"Current Value",each if Text.PositionOf(Custom1,_) <> -1 then "Transactional" else _}})
in
Custom2Thanks
Ankit Jain
Do Mark it as solution if the response resolved your problem. Do Kudo the response if it seems good and helpful.