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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Extract Using Any Non-Number As Delimiter

Hi. I am trying to extract numbers that only exist before any characters occur in the string. Once ANY characters start, that will be the end of the number. The trick here is that somtimes there are also numbers after the characters I want to use as a delimiter and should be ignored, so I simply can't use the function to extract all numbers. If there are no numbers before characters start, it would default to 1. Below are some examples:

 

SourceExtracted
30 30
40A 40
12,5CLR 12
ABC 1
ABC123

 1

 

I have attempted to use the Add Column --> Column From Examples function but it seems to revert to a simple "IF this value, THEN that value". Thanks!

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

= Table.AddColumn(#"Modificato tipo", "Personalizzato", each try Number.From(Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => c <"0" or c>"9")([Source]){0}) otherwise 1)

View solution in original post

@Anonymous , you need to add a new column this way in your senario,Untitled.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

8 REPLIES 8
CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , you might want try a simple solution

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZQitWJVjIxcATThkY6ps4+QWC2o5MzjDY0MlaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source = _t]),
    
    #"Added Custom" = Table.AddColumn(Source, "Extracted", each let str = List.First(Text.SplitAny([Source],Text.Remove([Source],{"0".."9"}))) in if str="" then 1 else Number.From(str))
in
    #"Added Custom"

 

Screenshot 2020-11-24 032516.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

Hi @CNENFRNL . Thanks for replying. When I create a new column with this code, it looks like my table turns into the exact image you provided. I do not need those exact values as they are examples to show the different scenarios of values I would need to convernt.

@Anonymous , you need to add a new column this way in your senario,Untitled.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!

Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

you can use this formula in a new column

let GetNumber=  List.FirstN(Text.ToList(_[Source]), (itemlist)=> Value.Is(try Number.From(itemlist) otherwise "text",type number) ) in if List.IsEmpty(GetNumber) then 1 else Number.From(Text.Combine(GetNumber))

 

here a complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZQitWJVjIxcATThkY6ps4+QWC2o5MzjDY0MlaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source = _t]),
    AddColumn = Table.AddColumn
    (
        Source,
        "Extract",
        each let GetNumber=  List.FirstN(Text.ToList(_[Source]), (itemlist)=> Value.Is(try Number.From(itemlist) otherwise "text",type number) ) in if List.IsEmpty(GetNumber) then 1 else Number.From(Text.Combine(GetNumber))
    )
in
    AddColumn

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Anonymous
Not applicable

 

= Table.AddColumn(#"previou step", "extract", each try Number.From(Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c))([Source]){0}) otherwise 1)

 

Anonymous
Not applicable

= Table.AddColumn(#"Modificato tipo", "Personalizzato", each try Number.From(Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => c <"0" or c>"9")([Source]){0}) otherwise 1)
Anonymous
Not applicable

Hi @Anonymous. All values in this column are showing up as 1 with this paritcular code.

Anonymous
Not applicable

mmhh ... I don't believe it. ‌🤔
Can you show the code you used and also the results obtained?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors