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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Combining Text.End and Text.Length in the same custom column in power query (M Language)

Hi, 

Say I have this simple table:

Example.png
And I want to extract the right part of the 'Bank ID' column starting at the 6th character into a new column.
In Excel I would use
=RIGHT(Table[@[Bank ID]],LEN(Table[@[Bank ID]])-5)

I've tried doing the same with M but got an error, 
can someone look at it and give me a fix:

2.png

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

Capture.JPG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

Capture.JPG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
smpa01
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1MzE2MlTSUXJJzAOSFhamZrompobGxvElxUqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, FN = _t, BankID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"FN", type text}, {"BankID", type text}}),
    #"Inserted Text Length" = Table.AddColumn(#"Changed Type", "Length", each Text.Length([BankID])-5),
    #"Added Custom" = Table.AddColumn(#"Inserted Text Length", "Custom", each Text.End([BankID],[Length]))
in
    #"Added Custom"
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Well, here's the bad news, that worked great.  It's possibly something to do with your data.  Maybe you could try adding those last two lines to a different dataset.  What error was returned at your side?

HotChilli
Super User
Super User

First thing, what does the error say?

 

For debugging, comment out the LEN stuff and hardcode the value, so that you can start to simplify your code,

and can you repost the contents of the Advanced Editor window?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors