Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Power Query Left String: Extract Text Steps

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Extracting the left portion of a text string in Excel Power Query is achieved using the `Text.Start` function. This method allows you to isolate specific characters from the beginning of a column, such as extracting area codes from phone numbers or product prefixes from SKUs, without altering the original source data.

What You'll Need

  • Microsoft Excel with Power Query enabled (available in Excel 2016 and later, or Office 365).
  • A dataset containing text columns from which you want to extract substrings.
  • Basic understanding of how to load data into the Power Query Editor.

Step-by-Step

  1. Load your data into Power Query: Select your data range in Excel, go to the Data tab, and click From Table/Range. If your data is not already formatted as a table, Excel will prompt you to create one; confirm this action to proceed.
  2. Select the target column: In the Power Query Editor window, locate the column that contains the text strings you wish to truncate. Click on the column header to select it entirely. Ensure the column type is set to Text; if it shows another type like Any, right-click the header, choose Change Type, and select Text.
  3. Access the Transform menu: With the column selected, navigate to the Transform tab in the ribbon at the top of the editor. Look for the Extract group within this tab.
  4. Choose the First Characters option: Click on the First Characters button. A dialog box will appear asking for the number of characters you want to retain from the start of each string.
  5. Specify the character count: Enter the integer value representing the length of the substring you need. For example, if you are extracting a three-digit country code, enter 3. Click OK to apply the transformation.
  6. Verify the output: The column will now display only the specified number of leading characters. Any existing text beyond this limit is removed. Check a few rows to ensure the extraction aligns with your expectations.
  7. Rename the column (Optional): If the extracted data represents a new field distinct from the original full string, double-click the column header and rename it appropriately (e.g., change "Full ID" to "Prefix").
  8. Close and Load: Go to the Home tab and click Close & Load. This returns the transformed data to a new worksheet in Excel, leaving your original source data untouched.

Common Mistakes

The most frequent error involves selecting the wrong column before applying the transformation. Because Power Query applies actions to the currently selected column, clicking First Characters while an unrelated numeric column is active can lead to unexpected results or errors. Always double-check the column header highlight before confirming any transform action.

Another common issue is ignoring data type consistency. If some cells contain numbers and others contain text, forcing a Text conversion might result in null values for certain entries depending on how Excel interprets the mixed types. It is crucial to clean and standardize data types before performing string extractions.

Users often forget that First Characters replaces the original content. If you need to keep the full string alongside the extracted part, you must duplicate the column first by right-clicking the header and selecting Duplicate Column, then apply the extraction to the copy.

Tips

For dynamic extraction where the number of characters varies per row, consider using custom columns with M code instead of the static UI buttons. You can use the formula = Text.Start([ColumnName], [NumberOfCharsColumn]) if you have a separate column defining the length for each record.

If you are extracting fixed-width fields, such as dates embedded in text, verify that your locale settings match the source data format. Power Query respects the regional settings of the machine running Excel, which can affect how text-to-date conversions behave after extraction.

Use the Applied Steps pane on the right side of the editor to track your progress. If you make a mistake, you can simply delete the last step rather than starting over. This non-destructive editing feature is one of Power Query's strongest advantages.

Troubleshooting

If the First Characters option is grayed out, ensure that you have selected a single column. Multi-column selections disable most transform options because they require specific context for each field. Click directly on one column header to enable the menu.

Errors displaying "Data Format Error" usually indicate that the column contains invalid characters or mixed types that cannot be cleanly converted to text. To resolve this, try filtering out blank rows or using Replace Errors under the Transform tab to substitute problematic values with nulls or placeholders before extraction.

If the output appears truncated incorrectly, check for hidden whitespace characters. Leading spaces count as characters. You may need to apply Trim or Clean functions from the Transform tab before running First Characters to remove invisible formatting artifacts.

Frequently Asked Questions

Can I extract more characters than exist in the string?

Yes. If you specify a number greater than the actual length of a text string, Power Query will return the entire string without throwing an error. It does not pad the result with spaces or zeros.

How do I extract the right side instead?

Use the Last Characters option found in the same Extract group on the Transform tab. The process is identical to extracting left-side characters, but it retains the specified number of characters from the end of the string.

Does this change my original Excel file?

No. Power Query works on a copy of the data loaded into the query engine. Your original worksheet remains unchanged unless you explicitly overwrite it or link back to the source differently.

Is there a keyboard shortcut for this?

There is no default direct keyboard shortcut for opening the First Characters dialog. However, you can access the ribbon quickly by pressing Alt, then navigating through the key tips displayed for the Transform tab.

Can I use this on non-text columns?

You should convert numeric or date columns to text first if you intend to treat them as strings. Applying text functions directly to non-text types may result in errors or unintended behavior depending on the underlying data structure.