Forum Discussion
Splitting Column values
- 7 months ago
Hi dommyw277 ,
Thanks for the screenshot that really helps. As per my guess, the Invalid identifier error is coming from the way the column name Inc/SR is being referenced. Because the column name contains a slash (/), Power Query requires the #"" format.
So anywhere you have- [Inc/SR]
please change it to - [#"Inc/SR"]And in your filter step
each [#"Inc/SR"] <> null and [#"Inc/SR"] <> ""Once the column is referenced with [#"...."] , the syntax error should be resolved.
Hope this helps please give it a try. If anything still comes up, feel free to share another screenshot and we can take a look.
So the file is a csv not an excel document so I cahnged the code to below however, i get an error :
let
Source = Csv.Document(){[Name="Data"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Inc/SR", each if Text.StartsWith([Remarks],"SR-",Comparer.OrdinalIgnoreCase) or Text.StartsWith([Remarks],"INC-",Comparer.OrdinalIgnoreCase) then [Remarks] else null),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Category", each if [#"Inc/SR"]=null then [Remarks] else null),
#"Filled Down" = Table.FillDown(#"Added Custom1",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each [#"Inc/SR"] <> null and [#"Inc/SR"] <> ""),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Remarks"})
in
#"Removed Columns"
Error:
Expression.Error: 0 arguments were passed to a function which expects between 1 and 5.
Details:
Pattern=
Arguments=[List]
Hi dommyw277 ,
Thanks for clarifying that the source file is a CSV.
The error you’re seeing is expected with this line:
Source = Csv.Document(){[Name="Data"]}[Content],
Unlike Excel, a CSV file doesn’t contain named tables (such as Data).
Csv.Document must be provided with the file contents, so referencing a table name will result in the error.
0 arguments were passed to a function which expects between 1 and 5
To resolve this, please use the Source step that Power Query automatically generates when you import the CSV file, and then apply the remaining transformation steps (Add Column, Fill Down, Filter, etc.) on top of that source.
Also, please double check the exact column name (for example, Remarks vs Coloum1) and ensure headers are promoted correctly.
Once the source step is corrected, the rest of the logic should work as expected.
Hope this helps..
- dommyw2777 months agoHelper V
Amazing thank you, Merry Christmas! 🙂
- dommyw2777 months agoHelper V
Sorry but i dont understand your reply.
The column is called RequestID, im not sure what i add where in the advanced editor?
- dommyw2777 months agoHelper V
This is what i have minus the top 2 lines which contain info i cant post eg source of files:
#"Removed Top Rows" = Table.Skip(#"Changed Type",5),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"RequestID", type text}, {"Request Mode", type text}, {"Technician", type text}, {"Created Time", type datetime}, {"Completed Time", type datetime}, {"Subject", type text}, {"Request Type", type text}})
#"Added Custom" = Table.AddColumn(Source, "Inc/SR", each if Text.StartsWith([RequestID],"SR-",Comparer.OrdinalIgnoreCase) or Text.StartsWith([RequestID],"INC-",Comparer.OrdinalIgnoreCase) then [RequestID] else null),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Category", each if [#"Inc/SR"]=null then [RequestID] else null),
#"Filled Down" = Table.FillDown(#"Added Custom1",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each [#"Inc/SR"] <> null and [#"Inc/SR"] <> ""),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"RequestID"})
in
#"Changed Type1"I then get an error:
Expression.SyntaxError: Token ',' expected.
- V-yubandi-msft7 months agoCommunity Support
Hi dommyw277 ,
Thank you for sharing your query it helps make the issue clearer. The syntax error you encountered is caused by a few formatting issues in the M code.
1. There is a missing comma after the #"Changed Type1" step.
2. The Added Custom step should reference the previous step (#"Changed Type1") instead of Source.
3. The in statement should return the final step in the query.
Below is the corrected version with these changes made.
#"Removed Top Rows" = Table.Skip(#"Changed Type",5), #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes( #"Promoted Headers", { {"RequestID", type text}, {"Request Mode", type text}, {"Technician", type text}, {"Created Time", type datetime}, {"Completed Time", type datetime}, {"Subject", type text}, {"Request Type", type text} } ), #"Added Custom" = Table.AddColumn( #"Changed Type1", "Inc/SR", each if Text.StartsWith([RequestID], "SR-", Comparer.OrdinalIgnoreCase) or Text.StartsWith([RequestID], "INC-", Comparer.OrdinalIgnoreCase) then [RequestID] else null ), #"Added Custom1" = Table.AddColumn( #"Added Custom", "Category", each if [Inc/SR] = null then [RequestID] else null ), #"Filled Down" = Table.FillDown(#"Added Custom1", {"Category"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each [Inc/SR] <> null and [Inc/SR] <> ""), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows", {"RequestID"}) in #"Removed Columns"Once these small fixes are applied, the syntax error should be resolved. If anything still looks off, please let us know what error message you see next.
Regards,
Yugandhar.
- dommyw2777 months agoHelper V
thnak you but I get this error:
Expression.SyntaxError: Invalid identifier.
- V-yubandi-msft7 months agoCommunity Support
Thank you for the update.
The Expression.SyntaxError: Invalid identifier message usually indicates a small formatting issue in the M code, such as1. A missing comma or parenthesis, or
2. A step name that doesn’t match the one used in the in statement.
Power Query normally highlights the problematic line in red. Could you please share a screenshot of the line that Power Query marks as the error.
Once we can see the highlighted line, it will be easier to identify the solution.
Regards,
Yugandhar.
- dommyw2777 months agoHelper V
- V-yubandi-msft7 months agoCommunity Support
Hi dommyw277 ,
Thanks for the screenshot that really helps. As per my guess, the Invalid identifier error is coming from the way the column name Inc/SR is being referenced. Because the column name contains a slash (/), Power Query requires the #"" format.
So anywhere you have- [Inc/SR]
please change it to - [#"Inc/SR"]And in your filter step
each [#"Inc/SR"] <> null and [#"Inc/SR"] <> ""Once the column is referenced with [#"...."] , the syntax error should be resolved.
Hope this helps please give it a try. If anything still comes up, feel free to share another screenshot and we can take a look.