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

Removing variable amount of characters from front of cell

Hi all!

 

I'm working with badge numbers, and some of our badges start with either one letter, two letters, or none at all.

 

Joe ShmoZZ1234125
Derrick DieterZ23412344
Paul Piper124244444
Aaron Iron124321441
Bowlsey Bollsly564234123

 

Is there any way that I can create something that recognizes the first few characters as letters and, if there aren't none, to leave the cell alone?

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcwxC8JADIbhvxIyd0kudbd00ang1uOGIgEPoyfXivTf26bf8C4PfDHitSjcHq+CDY4jcRDiFlMTsdda8/0JfdZF686OQcR5mL4GQ/44EQvLPqfzVMsbLlsOCkwi5NSVn826QlfMZls3b09y/GJKfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Badge = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Num Only", each Text.Select([Badge], {"0".."9"}))
in
    #"Added Custom"

Screenshot 2021-06-24 195845.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
negi007
Community Champion
Community Champion

@Anonymous you can create a column like below in your data

 

Column =
var chr_1 = MID('Table'[badge ],1,1)*1
var chr_2 = MID('Table'[badge ],2,1)*1
var chr_3 = MID('Table'[badge ],1,2)*1
var ctr = ISERROR(chr_1)+ISERROR(chr_2)

return
MID('Table'[badge ],1,ctr)
 
 
negi007_0-1624557604144.png

 




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcwxC8JADIbhvxIyd0kudbd00ang1uOGIgEPoyfXivTf26bf8C4PfDHitSjcHq+CDY4jcRDiFlMTsdda8/0JfdZF686OQcR5mL4GQ/44EQvLPqfzVMsbLlsOCkwi5NSVn826QlfMZls3b09y/GJKfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Badge = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Num Only", each Text.Select([Badge], {"0".."9"}))
in
    #"Added Custom"

Screenshot 2021-06-24 195845.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Thanks! Worked like a charm and I was able to link the id with another table in order to pull their names into a bigger dataset.

@Anonymous You can also try below way

 

Column =
var chr_1 = MID('Table'[badge ],1,1)*1
var chr_2 = MID('Table'[badge ],2,1)*1
var chr_3 = len('Table'[badge ])*1
var ctr = (ISERROR(chr_1)+ISERROR(chr_2))*1

return
//chr_3
//ctr

MID('Table'[badge ],ctr+1,chr_3-ctr)
 
negi007_0-1624592838099.png

 




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

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.