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
Craig
Helper I
Helper I

Need help with a PowerQuery formula

Hello Experts,

 

Need help to write a powerquery formula that tests the following in power query editor

 

If the last 5 characters of a field are values (1..9) then extract into a new column the 2 characters immediately before the first value, otherwise leave the cell blank (null)

for example

existing field                                             new field (column)                                                 

PA19103                                                    PA

China                                                         null

CA95402                                                    CA

India                                                           null

 

thank you for any assistance!!

 

Craig

1 ACCEPTED SOLUTION

 

@Craig 

 

Alternatively: in 1 step: 

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each try  Number.From( Text.End([Column1],5)) otherwise null)
in
    #"Added Custom"

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

View solution in original post

3 REPLIES 3
adudani
Memorable Member
Memorable Member

HI @Craig ,

 

Paste this in the advanced editor of a blank query:

 

let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Inserted Last Characters" = Table.AddColumn(#"Changed Type", "Last Characters", each Text.End([Column1], 5), type text),
#"Changed Type1" = Table.TransformColumnTypes(#"Inserted Last Characters",{{"Last Characters", Int64.Type}}),
#"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type1", {{"Last Characters", null}})
in
#"Replaced Errors"

 

 

Please let me know if this resolves the question.

 

Appreciate a thumbs up if this is helpful.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

 

@Craig 

 

Alternatively: in 1 step: 

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each try  Number.From( Text.End([Column1],5)) otherwise null)
in
    #"Added Custom"

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

thank you very much...it was very helpful!!

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.