Skip to content

Instantly share code, notes, and snippets.

@IvanBond
Last active March 7, 2024 13:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save IvanBond/de5d947421fbfaaf0e8e45c628b01836 to your computer and use it in GitHub Desktop.
Save IvanBond/de5d947421fbfaaf0e8e45c628b01836 to your computer and use it in GitHub Desktop.
PowerTrim function for Power Query
/*
Function removes double presents of specified characters.
By default remove double spaces and leading + ending spaces.
Like TRIM function in Excel
Original is taked from Ken Puls's blog
http://www.excelguru.ca/blog/2015/10/08/clean-whitespace-in-powerquery/
*/
// part of repository: https://github.com/IvanBond/pquery
(text as text, optional char_to_trim as text) =>
let
char = if char_to_trim = null then " " else char_to_trim,
split = Text.Split(text, 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