Text.StartsWith Function in Power Query

In Power Query (M language), the Text.StartsWith function is used to determine whether a given text string starts with a specified substring.

Syntax

Text.StartsWith(
    text as nullable text, 
    substring as text, 
    optional comparer as nullable function
) as nullable logical

The function has the following parameters:

Returns:

Example: Basic Case-Sensitive Check

Power Query M

let
    result = Text.StartsWith("PowerQuery", "Power")
in
    result    

The above code returns the result true.

Example: Case-Sensitive Mismatch

Power Query M

let
    Result = Text.StartsWith("PowerQuery", "power")
in
    Result    

The above code returns the result false.

Example: Case-Insensitive Check

Power Query M

let
    Result = Text.StartsWith("PowerQuery", "power", Comparer.OrdinalIgnoreCase)
in
    Result    

The above code returns the result true.

Example: Using in a Table Column (Add Column Example)

Power Query M

let
    // Example table
    Source = Table.FromRecords({
        [Column1="PowerQuery"],
        [Column1="PQTools"],
        [Column1="QueryPower"]
    }),
    
    // Add column to check if Column1 starts with "PQ"
    AddedColumn = Table.AddColumn(Source, "StartsWithPQ", each Text.StartsWith([Column1], "PQ"))
in
    AddedColumn   

The output of the above code is shown below:

Column1StartsWithPQ
PowerQueryfalse
PQToolstrue
QueryPowerfalse