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

Be 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

Reply
amdi_silword
Frequent Visitor

unknown identifier - use the [field] shorthand for a _[field] outside

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.

Table.PNG

 

 

 

 

 

 

 

 

 

 

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

 

 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

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.

View solution in original post

4 REPLIES 4
HotChilli
Super User
Super User

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!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors