Pinterest Pixel

Replicating Excel’s LEN Function with M in Power Query

Bryan
When working with data, one of the key tasks is to know the length of text entries.
Power Query provides a simple way to count the length of a text.

In this article, I will show you how to replicate LEN function with M in Power Query.

When working with data, one of the key tasks is to know the length of text entries. Power Query provides a simple way to count the length of a text. In this article, I will show you how to replicate LEN function with M in Power Query.

Key Takeaways:

  • LEN function counts the number of characters in a string.
  • In Power Query, Text.Length() is the equivalent of the LEN function.
  • Text.Length function counts letters, numbers, spaces, and punctuation.
  • Go to Add Column > Custom Column to create a text length calculation.
  • Character counts can help with data validation, cleaning, and analysis.

 

Download excel workbookReplicating-Excels-LEN-Function-with-M.xlsx

LEN Function in Excel

What is LEN and How Does it work?

The LEN function in Excel is used to return the number of characters in a text string. The syntax of this function is:

=LEN(text)

Excel counts and displays the total number of characters, including spaces, punctuation, and numbers.

Excel's LEN Function with M in Power Query

Why Use LEN in Data Analysis?

The LEN function is a key tool in data analysis for several reasons.

  • It allows us to verify the consistency and accuracy of data entries by checking their length.
  • It can be used to identify and resolve data quality issues.
  • It can also be used to clean, validate, and format data.

 

Creating a Custom LEN Function in Power Query

STEP 1: Select your data and go to Insert > Table.

Replicating Excel's LEN Function with M in Power Query

STEP 2: Go to Data > Get & Transform > From Table

Excel 2016:

 Excel's LEN Function with M in Power Query

Excel 2013 & 2010:

Go to Power Query > Excel Data > From Table (Excel 2013 & 2010)

Excel's LEN Function with M in Power Query

STEP 3: This will open up the Power Query Editor.

We want to get the length of the Channel Partners, so we need to select the CHANNEL PARTNERS column.

Go to Add Column > Add Custom Column

Replicating Excel's LEN Function with M in Power Query

STEP 4: Let us create a simple M expression to replicate the LEN function in Excel.

  • In the New column name text box, type CHANNEL PARTNERS (LEN)
  • In the Custom column formula, type in: Text.Length(
  • From the Available columns choose CHANNEL PARTNERS and select Insert.
  • Then finish off the formula by entering  

We now have build the following formula: Text.Length([CHANNEL PARTNERS])

So lets quickly break down what we just did:

  • We are using the Text.Length formula to get the length of the CHANNEL PARTNERS column
  • Click OK to confirm.

Replicating Excel's LEN Function with M in Power Query

Now you will see your changes take place.

Replicating Excel's LEN Function with M in Power Query

STEP 5: Click Close & Load

Replicating Excel's LEN Function with M in Power Query

Congratulations! You have used a M formula for replicating the LEN function!

Replicating Excel's LEN Function with M in Power Query

 

Practical Uses of Text.Length in Power Query

Text.Length is useful for validating and cleaning data. For example, you can check whether customer IDs, postal codes, or product codes meet a required character length. It can also help identify unusually short or long text entries that may contain errors.

You can use these character counts to filter records, improve data quality, and prepare data for systems that have character limits

 

FAQs

1. What is the Power Query equivalent of the LEN function?

The Power Query equivalent of LEN is Text.Length function.

2. Does Text.Length count spaces?

Yes, it counts all characters, including spaces and punctuation.

3. How to use Text.Length in Power Query?

  • Open your data in Power Query Editor.
  • Go to Add Column > Custom Column.
  • Enter the formula: Text.Length([Column Name]).
  • Click OK to create the new column.

4. Can I count the length of numbers with Text.Length?

Yes, but you may need to convert the numbers to text first.

5. Why would I use Text.Length in Power Query?

It helps validate, clean, and analyze text data based on character count.

If you like this Excel tip, please share it




Bryan

Bryan Hong is an IT Software Developer for more than 10 years and has the following certifications: Microsoft Certified Professional Developer (MCPD): Web Developer, Microsoft Certified Technology Specialist (MCTS): Windows Applications, Microsoft Certified Systems Engineer (MCSE) and Microsoft Certified Systems Administrator (MCSA).

He is also an Amazon #1 bestselling author of 4 Microsoft Excel books and a teacher of Microsoft Excel & Office at the MyExecelOnline Academy Online Course.

See also  Extract Length Using Power Query or Get & Transform

Star 30 Days - Full Access Star

One Dollar Trial

$1 Trial for 30 days!

Access for $1

Cancel Anytime

One Dollar Trial
  • Get FULL ACCESS to all our Excel & Office courses, bonuses, and support for just USD $1 today! Enjoy 30 days of learning and expert help.
  • You can CANCEL ANYTIME — no strings attached! Even if it’s on day 29, you won’t be charged again.
  • You'll get to keep all our downloadable Excel E-Books, Workbooks, Templates, and Cheat Sheets - yours to enjoy FOREVER!
  • Practice Workbooks
  • Certificates of Completion
  • 5 Amazing Bonuses
Satisfaction Guaranteed
Accepted paymend methods
Secure checkout

Get Video Training

Advance your Microsoft Excel & Office Skills with the MyExcelOnline Academy!

Dramatically Reduce Repetition, Stress, and Overtime!
Exponentially Increase Your Chances of a Promotion, Pay Raise or New Job!

Learn in as little as 5 minutes a day or on your schedule.

Learn More!

Share to...