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.
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
TrimAllTxtCols
This 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.
It's taken me a while to come back to this and try it out.
It worked perfectly. You are brilliant as always!