Forum Discussion
meierli
Helper I
2 years agoCombine 4 M-Codes into 1
i have 4 different m-codes all achiving the same result just with slight;y different "lookup" values (see bottom of message) and would like to combine them all into one m-code if possible. m-code...
- 2 years ago
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "jY/NaoNQEEZfZdCtifNzr/eOu0RNI20TUUMI4iJQS6E0hTYU+vbVdidZdBbf6hw403VBtr0PAcUtkFTESWI9tKeqSEGdB6SYNGYT9FEXVKsTPJS7okkpGjUI2SDSmnA857xxiLe5CTDJCJuo3LVFXTQtrB7bFGgpMwVSjszCQnUH6wzqwy606hzYKWZKFWZV8WrN3KPJOWz/JFUiGIfhuP/1qDmSYfTiDew3m6Zob6d6FrE69pKSkP4Lmj0ly7k3xeV5XA9fw8fn8ATl5fkdqvP323C5QvbyGorhRIXVQn5NAU1MFDOyBH3/Aw==", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Transaction_Comment = _t] ), #"Added Custom4" = Table.AddColumn( Source, "Custom.4", each Text.Trim( Text.AfterDelimiter(Text.AfterDelimiter(Text.Upper([Transaction_Comment]), "CHK"), "#") ) ), #"Split Column by Character Transition" = Table.SplitColumn( #"Added Custom4", "Custom.4", Splitter.SplitTextByCharacterTransition( {"0" .. "9", "A" .. "Z", "-"}, (c) => not List.Contains({"0" .. "9", "A" .. "Z", "-"}, c) ), {"CHK#"} ) in #"Split Column by Character Transition"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.
lbendlin
Super User
2 years agono, all you need is
#"Added Custom4" = Table.AddColumn(
Source,
"Custom.4",
each Text.Trim(
Text.AfterDelimiter(Text.AfterDelimiter(Text.Upper([Transaction_Comment]), "CHK"), "#")
)
),
#"Split Column by Character Transition" = Table.SplitColumn(
#"Added Custom4",
"Custom.4",
Splitter.SplitTextByCharacterTransition(
{"0" .. "9", "A" .. "Z", "-"},
(c) => not List.Contains({"0" .. "9", "A" .. "Z", "-"}, c)
),
{"CHK#"}
)
in
#"Split Column by Character Transition"
assuming you have a Source step that has a [Transaction_Comment] column.
meierli
Helper I
2 years agoi copied the code into the advanced editor and once it runs, I get enclosed error. i don't follow on the error since the column "transaction_comment" is in my source file. what am i doing wrong?
- lbendlin2 years ago
Super User
check for extra spaces after the column name. You may also have to escape the underscore as [#"Transaction_Comment"]
- meierli2 years ago
Helper I
i dont see any extra spaces after the column name and the name of the column does have an underscore.
- lbendlin2 years ago
Super User
#"Added Custom4" = Table.AddColumn( Source, "Custom.4", each Text.Trim( Text.AfterDelimiter(Text.AfterDelimiter(Text.Upper([#"Transaction_Comment"]), "CHK"), "#") ) ),