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.
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:
Source | Extracted |
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!
Solved! Go to Solution.
= Table.AddColumn(#"Modificato tipo", "Personalizzato", each try Number.From(Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => c <"0" or c>"9")([Source]){0}) otherwise 1)
@kyleb350 , you need to add a new column this way in your senario,
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, @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"
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,
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! |
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
= Table.AddColumn(#"previou step", "extract", each try Number.From(Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c))([Source]){0}) otherwise 1)
= 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.
mmhh ... I don't believe it. 🤔
Can you show the code you used and also the results obtained?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.