Skip to content

Instantly share code, notes, and snippets.

@Mike-Honey
Last active April 19, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mike-Honey/82240072383479d219978613342ea548 to your computer and use it in GitHub Desktop.
Save Mike-Honey/82240072383479d219978613342ea548 to your computer and use it in GitHub Desktop.
// Based on Ken Puls' blog post - http://www.excelguru.ca/blog/2015/10/08/clean-whitespace-in-powerquery/
// Trims in the style of the Excel TRIM function - embedded whitespace is trimmed to a single space.
// This variation accepts null values in the text parameter, in which case it returns an empty string.
(optional text as text, optional char_to_trim as text) =>
let
char = if char_to_trim = null then " " else char_to_trim,
text2 = if text = null then " " else text,
split = Text.Split(text2, char),
removeblanks = List.Select(split, each _ <> ""),
result=Text.Combine(removeblanks, char)
in
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment