Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Error message using List

Hi

 

I'm creating an M language demo on text functions. Iniitally I show this, a simple extract of the first 8 characters of "Customer Name", which demonstarrtes how this doesn't quite work like Excel LEFT, i.e it returns "Error" when the source string is ess than 8 characters:

 

M Working shortname.PNG

 

As an alternative, I am attempting to use the "List.min" function to get a short version of the Customer name the same length as the shortest Csutomer name, but am getting "Error" instead:

 

Text Len Q.PNG

Can anyone help?

 

Thanks!

1 REPLY 1
OwenAuger
Super User
Super User

Hi @Anonymous 

 

Not sure if you tried Text.Start? When the number of characters specified is greater than the length of the string, the entire string will be returned without error.

 

To make this work with Text.Range, you would actually have to transform the list of Customer names into a list of lengths, then take the minimum of those.

 

Here is the code (formatted for readability):

 

 

= Table.AddColumn(
  #"Removed Other Columns",
  "Custom",
  each Text.Range(
    [Customer],
    0,
    List.Min(
      List.Transform(
        #"Removed Other Columns"[Customer],
        Text.Length
      )
    )
  )
)

Since the above code would re-evaluate the same minimum length for every row of the table, you could instead write this to evaluate the minimum length once only:

 

= let MinLength =
List.Min(
  List.Transform(
    #"Removed Other Columns"[Customer],
    Text.Length
  )
)
in
Table.AddColumn(
  #"Removed Other Columns",
  "Custom",
  each Text.Range(
    [Customer],
    0,
    MinLength
  )
)

Regards,
Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.