Title: Replicate Excel's TRIM Function In Power Query | How To Excel
Headings: Replicate Excel’s TRIM Function In Power Query
Replicate Excel’s TRIM Function In Power Query
Table of Contents
The Problem
Video Tutorial
M Code For The Query Function
Create A Blank Query
Add M Code To The Advanced Editor
Using The Query Function
Conclusions

Content: Trim (Result) in ExcelTrim
This function takes a string of text and replaces double spaces with single spaces and repeats the process recursively until it doesn’t find any more double spaces. Then it applies the Text. Trim function to take care of any leading or trailing space characters. Creating a recursive function solves the problem of manually applying repeated Replace Values steps to remove double spaces and is a much more elegant and re-usable solution. Create A Blank Query
The first step to creating a query function is to create a new blank query. This is where we will place the M code for our function. Go to the Data tab ➜ then go to Get Data ➜ Choose From Other Sources ➜ then choose Blank Query. This will open up the power query editor. We can give the query a name using the Name box in the Properties section. This is what will be used to reference the query function, so we should give it a good descriptive name.