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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to extract ID numbers from a text string?

Hi,
@ImkeF
@Zubair_Muhammad

Now I’m trying to solve a slightly more complex situation. I’m trying to extract the 5 and 6 length ID numbers for UK and France.



This is my current approach.

Each country has a set of rules;

UK
1) Cut off first 3 characters from the string
2) Cut off all characters before and including /
3) Cut off all characters after and including ?

FR
1) Cut off first 4 characters from the string
2) Cut off all characters before and including @
3) Cut off all character after and including ?

So then I follow this procedure;

ID =

// Var UK
Var UK1 = Cut off first 3 characters from the string
Var UK2 = Cut off all characters before and including /
Var UK3 = Cut off all characters after and including ?
Var UK = Var UK 3

// Var FR
Var FR1 = IF(Page = Var UK THEN Var UK ELSE Cut off first 3 characters from the string)
Var FR2 = Cut off all characters before and including @
Var FR3 = Cut off all character after and including ?
Var FR = Var FR 3

// Var ID
Var ID = Var FR

Return
Var ID

Am I working in the most efficient way? Are there better solutions?

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous

 

Try this. I am not 100% sure.

Please could you paste data in copiable format instead if image

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCvXWL0tMTsxLrtS3NDQyMrPX003NLcjJr0xNVYrViVZyC3LUBwtkFqcUJ6YkGpkYx5QaGBin6jtYGIKAia6evlJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Page = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Page", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Start([Page],2)="UK" then
                                                                    Text.BetweenDelimiters([Page],"/", "?",1)
                                                                    else
                                                                    if Text.Start([Page],3)="FRA"
                                                                    then
                                                                    Text.BetweenDelimiters([Page],"@", "-")
                                                                    else
                                                                    null)
    in
    #"Added Custom"

 


Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous

 

Try this. I am not 100% sure.

Please could you paste data in copiable format instead if image

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCvXWL0tMTsxLrtS3NDQyMrPX003NLcjJr0xNVYrViVZyC3LUBwtkFqcUJ6YkGpkYx5QaGBin6jtYGIKAia6evlJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Page = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Page", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Start([Page],2)="UK" then
                                                                    Text.BetweenDelimiters([Page],"/", "?",1)
                                                                    else
                                                                    if Text.Start([Page],3)="FRA"
                                                                    then
                                                                    Text.BetweenDelimiters([Page],"@", "-")
                                                                    else
                                                                    null)
    in
    #"Added Custom"

 


Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

@Zubair_Muhammad

Thanks very much. I will try tommorow morning.
Yes, I will paste the data in the right format tommorow morning.

Thanks again

Anonymous
Not applicable

@Zubair_Muhammad

It works ! 🙂

Thanks very much. I'm learning a lot about text extraction.



Now, I hope I can solve the full problem I have.

Hopefully you can help me with the last steps 🙂

Data

UK/vacancy/91226?.-employee<af44g>3.3u22u37666fff_91226
UK/vacancy-employee</21226?.->3.3.u376641 fff21226
UK/vacancy-employee155-</44226?>3.3uu37ff54215f_44226
FRA/emplois vacants.employé.243>/@811114-./3uu37ff263337f_?811114
FRA/emplois vacants /employé?<af4fg>aa/@833114-./uu37ff443211f_?833114
FRA/emplois vacants/employé?a3f44>3. /@133114-./ff4121_?155654133114
UK/vacancy.11-employee<af4fg>3.3u76117u37fff_/79856?79856
UK/vacancy-employee<44>3F/91156?.3.u344447f87ff_91156
FRA/emplois vacants /employé?<af4fg>aa/@133114-./uu37f6442251ff_?133114
FRA/emplois vacants /employé?a568>3./@187114-./711112 ff_? 187114

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.