cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Ido Frequent Visitor
Frequent Visitor

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

Accepted Solutions
smpa01 Senior Member
Senior Member

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

4 REPLIES 4
HotChilli New Contributor
New Contributor

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

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?

smpa01 Senior Member
Senior Member

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

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"
HotChilli New Contributor
New Contributor

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

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?

smpa01 Senior Member
Senior Member

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

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)