Power Query Split Column Dynamically

vilnukoy

New Member
Joined
Feb 16, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have the following code for splitting a column:

let
Source = Folder.Files("C:\Users\XXXX\Desktop\Athena Reports"),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),
#"Filtered Rows" = Table.SelectRows(#"Expanded Table Column1", each true),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"S:No", "Origin ID", "Origin Name"}),
#"Duplicated Column1" = Table.DuplicateColumn(#"Removed Columns", "Check Number", "Check Number - Copy"),
#"Replaced Value" = Table.ReplaceValue(#"Duplicated Column1","#","",Replacer.ReplaceText,{"Check Number - Copy"}),
#"Trimmed Text" = Table.TransformColumns(#"Replaced Value",{{"Check Number - Copy", Text.Trim, type text}}),
#"Duplicated Column" = Table.DuplicateColumn(#"Trimmed Text", "RCM Posting History", "RCM Posting History - Copy"),
#"Filtered Rows1" = Table.SelectRows(#"Duplicated Column", each true),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Filtered Rows1"),
SplitByDelimiter = (table, column, delimiter) =>
let
Count = List.Count(List.Select(Text.ToList(Table.Column(table, column){0}), each _ = delimiter)) + 1,
Names = List.Transform(List.Numbers(1, Count), each column & "." & Text.From(_)),
Types = List.Transform(Names, each {_, type text}),
Split = Table.SplitColumn(table, column, Splitter.SplitTextByDelimiter(delimiter), Names),
Typed = Table.TransformColumnTypes(Split, Types)
in
Typed,
#"Split Column by Delimiter" = SplitByDelimiter("RCM Posting History - Copy","~")
in
#"Split Column by Delimiter"

BUT keep getting the following error:

Expression.Error: 2 arguments were passed to a function which expects 3.
Details:
Pattern=
Arguments=


  • Can anybody help on this??
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Example of info in RCM Posting History - Copy

10/11/2023 04:33:02 PM~CGutierrez~Manual~REVERSED PAYMENT ERROR~07/03/2023~($23.46)~SUCCESSFUL|10/11/2023 04:32:01 PM~CGutierrez~Manual~COVID PAYMENT~07/03/2023~$23.46~SUCCESSFUL|10/11/2023 04:31:34 PM~CGutierrez~Manual~COVID PAYMENT~07/03/2023~$23.46~SUCCESSFUL|
 
Upvote 0
Your custom function needs 3 variables. You used just 2 in the line below

SplitByDelimiter("RCM Posting History - Copy","~")
 
Upvote 0
You need to provide table, column and delimiter according to the input definition of the function M-code. You gave it a table and the delimiter.
 
Upvote 0
You need to provide table, column and delimiter according to the input definition of the function M-code. You gave it a table and the delimiter.
Can you point that out in the code?
 
Upvote 0
After that line SplitByDelimiter...
 
Upvote 0
SplitByDelimiter = (table, column, delimiter) =>
Table would be previous step I guess.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top