Splitter.SplitTextByRepeatedLengths

D

T

The M Code Behind the Power Query M function Splitter.SplitTextByRepeatedLengths

Understanding the Power Query M Language

Power Query is a data transformation and cleaning tool that is part of the Microsoft Power BI suite. Power Query uses the M language to transform and shape data. M is a functional programming language that is used to write custom functions and perform complex data transformations in Power Query.

In order to fully understand the code behind Splitter.SplitTextByRepeatedLengths, it is important to have a basic understanding of the M language. M is a case-sensitive language and is based on functional programming concepts such as immutability, recursion, and higher-order functions.

Using Splitter.SplitTextByRepeatedLengths

Splitter.SplitTextByRepeatedLengths is a function that splits text into equal-length chunks. This function takes two arguments: the text to be split and the length of each chunk. For example, if we wanted to split the word “hello” into two equal-length chunks, we would use the following code:


Splitter.SplitTextByRepeatedLengths("hello", 2)


This would return the following output:


{"he", "ll", "o"}


As you can see, the word “hello” has been split into three equal-length chunks of two characters each.

The M Code Behind Splitter.SplitTextByRepeatedLengths

Splitter.SplitTextByRepeatedLengths is a built-in function in Power Query, which means that the code behind it is not accessible to users. However, we can still gain a basic understanding of the code by examining the function’s behavior.

When Splitter.SplitTextByRepeatedLengths is called, the M engine first converts the input text into a list of characters. It then calculates the number of chunks that will be created based on the length of the input text and the specified chunk size. Finally, it uses the List.Generate function to generate each chunk.

The List.Generate function is a powerful tool in M that allows users to generate lists using custom logic. In the case of Splitter.SplitTextByRepeatedLengths, List.Generate is used to loop through the list of characters and generate each chunk.

Tips and Tricks for Using Splitter.SplitTextByRepeatedLengths

Splitter.SplitTextByRepeatedLengths is a versatile function that can be used to manipulate text data in a variety of ways. Here are some tips and tricks for using Splitter.SplitTextByRepeatedLengths in your Power Query projects:

– If you want to split text into equal-length chunks but are not sure what length to use, try using the Text.Length function to determine the length of the input text and divide it by the number of chunks you want to create.

– If your input text contains whitespace or special characters, you may need to use the Text.Remove function to clean the text before using Splitter.SplitTextByRepeatedLengths.

– If you want to split text into chunks of varying lengths, you can use the List.Generate function to generate custom logic for creating each chunk.

Splitter.SplitTextByRepeatedLengths is a powerful function in Power Query that allows users to split text into equal-length chunks. While the M code behind Splitter.SplitTextByRepeatedLengths is not accessible to users, a basic understanding of the function’s behavior can be useful for optimizing your Power Query projects. By following the tips and tricks outlined in this article, you can become more proficient at using Splitter.SplitTextByRepeatedLengths and manipulating text data in Power Query.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)