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
kyleb350
Helper I
Helper I

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

@kyleb350 , 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, @kyleb350 , 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!

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.

@kyleb350 , 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 @kyleb350 

 

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)

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
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.

Top Solution Authors
Top Kudoed Authors