March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi
I want to replace the first 4 characters with other 4 xxx- in column SSN. so it will look lihe this xxx-23-2193 and so on.
M Kode is:
let
Source = Excel.Workbook(File.Contents("C:\Users\Bruger\OneDrive\DAX\KIT Edit Query\Skift de 4 første Digit-Curbal\Tabel.xlsx"), null, true),
TabelAmdiTest_Table = Source{[Item="TabelAmdiTest",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(TabelAmdiTest_Table,{{"ID", Int64.Type}, {"Name", type text}, {"SSN", type text}}),
#"Replace first 4 charaters" = Table.ReplaceValue(#"Changed Type", Text.Replace([SNN],Text.Start([SSN],4),"XXX-"))
in
//#"Changed Type"
#"Replace first 4 charaters"
In the row just above in: Text.Replace([SNN],Text.Start([SSN],4),"XXX-")
The code generate the error:
Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?
Appriciate if one could guide in this.
Link to the pbix file Pbix file I thought I could attach a file. therefore a link.
Thanks
Amdi
Solved! Go to Solution.
After a bit of experimentation I came up with this:
Table.TransformColumns(#"Changed Type", {"SSN", each Text.ReplaceRange(_, 0, 4 ,"XXX-"), type text} )
This should make the change in place.
I started out by adding a column with Text.ReplaceRange([SSN], 0, 4 ,"XXX-") to see if that worked.
You can test with your own data.
After a bit of experimentation I came up with this:
Table.TransformColumns(#"Changed Type", {"SSN", each Text.ReplaceRange(_, 0, 4 ,"XXX-"), type text} )
This should make the change in place.
I started out by adding a column with Text.ReplaceRange([SSN], 0, 4 ,"XXX-") to see if that worked.
You can test with your own data.
How might this work with a nested if. I'm getting the same error but with 5 nested ifs. Not sure where the "each" goes.
Hi HotChili
Many thanks for your support.
/Amdi
Thanks for your help Amdi. Whatever glitch was happening yesterday, it seems to be working today. I really appreiate your help!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.