Text.TrimStart

Updated on

Text.TrimStart is a Power Query M function that removes leading whitespace from a text value. The function returns the modified text value with the leading whitespace removed.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Text.TrimStart(
   text as nullable text,
   optional trim as any,
) as nullable text

Description

The Text.TrimStart function removes unwanted characters from the beginning of a text string. By default, it trims whitespace, but it can also remove specific characters or a list of characters when specified.

Examples

Here are some examples on how to use the Text.TrimStart function:

Removing Leading Whitespace

The most straightforward use case for this function is to remove leading whitespace from a text string. When the second argument is not provided, the function defaults to trimming whitespace characters.

For instance, consider the string ” a b c d “. With Text.TrimStart, we can strip the leading spaces:

Text.TrimStart( "   a b c d    " ) // Returns "a b c d    "

Removing Specific Characters

In addition to spaces, you can instruct the function to remove any character from the start of a string. By specifying this character in the second argument, the function will only remove that particular character.

For example, the text “**gorilla**” has asterisks at both ends, but if you want to remove the asterisks only at the start, you would do as follows:

Text.TrimStart( "***gorilla***", "*" ) // Returns "gorilla***"

Removing Multiple Characters

There may be situations where you need to remove multiple different characters from the start of a string. In these cases, the function can accept a list of text values in the second argument, indicating the characters to be removed.

To illustrate, let’s say we want to get rid of both spaces and asterisks from “* * gorilla”. Passing both ” ” and “*” in a list to Text.TrimStart does the job perfectly:

Text.TrimStart( "* * gorilla", { " ", "*" } ) // Returns "gorilla"

Pushing the boundaries further, you can feed Text.TrimStart with a generated list to strip all lowercase letters from the start of a string:

Text.TrimStart( "pizzaHut", { "a" .. "z" } ) // Returns "Hut"

Learn more about Text.TrimStart in the following articles:

Other functions related to Text.TrimStart are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/text-trimstart

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy