Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowData Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more
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
Solved! Go to Solution.
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"
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.
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"
thank you very much...it was very helpful!!
Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.
Check out the May 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 1 |
| User | Count |
|---|---|
| 11 | |
| 11 | |
| 5 | |
| 4 | |
| 3 |