Forum Discussion
Cleaning Text field columns from incoming SQL database
- 2 years ago
Hi RobRayborn,
Let's try something else...
Create a new blank query and replace everything inside with the following code:
let TrimAllTxtCols = (t as table, optional n as number) as table => Table.TransformColumns( t, List.Transform( List.Select( Table.ColumnNames(t), each if n = null then List.MatchesAll( Table.Column(t, _), (x) => Value.Is(x, type nullable text) ) else List.MatchesAll( List.FirstN(List.RemoveNulls(Table.Column(t, _)), n), (x) => Value.Is(x, type text) ) ), each {_, Text.Trim, type text} ) ) in TrimAllTxtColsThis returns a function value, you can give this query a more suitable name if you like.
Now for "t" pass it query with your incoming SQL data
When you have many rows in your table, I'd encourage you to also pass a number for "n" that tells the function how many rows to check, to see if your column contains text values.Hope that works for you.
Cheers.
Should this come after the "Navigation" step?
It also keeps generating an error, - "Token '=' expected", which is apparently supposed to come after the Table.TransformColumns.
See the second example, where this code has been implemented.
It needs to come after the Navigation step BUT your columns have to be typed so when you see an "ABC123" beside your column names, you need to set column type first before applying it or use the second method illustrated in that example.
I hope this is helpful