Forum Discussion
Converting text (Replacing values) within multiple columns in Power Query
- 5 years ago
Hi dkernen ,
You can try this query:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUYpMLVbQKMhJTSxOVUjNK0ktUkiqVCjPyM/VtMIqW56RmZyhUJBRWZyZnJmYh6mqoiAnMROfeKxOtJITUBaCcOkFK3MeGAfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, UMD = _t, MD = _t, BDEarlyConv = _t, DCDPronIssues = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"UMD", type text}, {"MD", type text}, {"BDEarlyConv", type text}, {"DCDPronIssues", type text}}), #"AllReplace" = [ #"Yes (please enter by whom):"= "Yes", #"Yes (please enter which physician):" = "Yes", #"Yes (please explain):" = "Yes" ], #"Replace Value" = Table.TransformColumns( #"Changed Type", { {"UMD", each Record.FieldOrDefault(#"AllReplace",_,_),type text}, {"MD", each Record.FieldOrDefault(#"AllReplace",_,_),type text}, {"BDEarlyConv", each Record.FieldOrDefault(#"AllReplace",_,_),type text}, {"DCDPronIssues", each Record.FieldOrDefault(#"AllReplace",_,_),type text} } ) in #"Replace Value"Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
dkernen Could you just split the columns by the first space and dump the extra columns?
- dkernen5 years agoResolver II
Greg - thank you for you swift reply! Definitely I could strip out anything after the first space (if a space exists). Are you suggesting that I create new dummy columns, then delete the ones I don't need, and then rename the new one? I was perhaps hoping I could do it all in one step. Is that not possible?
- v-yingjl5 years agoCommunity Support
Hi dkernen ,
You can try this query:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUYpMLVbQKMhJTSxOVUjNK0ktUkiqVCjPyM/VtMIqW56RmZyhUJBRWZyZnJmYh6mqoiAnMROfeKxOtJITUBaCcOkFK3MeGAfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, UMD = _t, MD = _t, BDEarlyConv = _t, DCDPronIssues = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"UMD", type text}, {"MD", type text}, {"BDEarlyConv", type text}, {"DCDPronIssues", type text}}), #"AllReplace" = [ #"Yes (please enter by whom):"= "Yes", #"Yes (please enter which physician):" = "Yes", #"Yes (please explain):" = "Yes" ], #"Replace Value" = Table.TransformColumns( #"Changed Type", { {"UMD", each Record.FieldOrDefault(#"AllReplace",_,_),type text}, {"MD", each Record.FieldOrDefault(#"AllReplace",_,_),type text}, {"BDEarlyConv", each Record.FieldOrDefault(#"AllReplace",_,_),type text}, {"DCDPronIssues", each Record.FieldOrDefault(#"AllReplace",_,_),type text} } ) in #"Replace Value"Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - Greg_Deckler5 years agoCommunity Champion
dkernen 1 Step:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqkwtVkgsTklLLFaK1YFyk3ISFRKBZIpCamJKIkI8JRskkZMGlIQjpdhYAA==", 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}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Column1.1"}) in #"Split Column by Delimiter"