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.
I'm expanding a User Defined Function. The original function extract and returns only integers from a string, i.e. social security numbers, phone numbers.
I need to add logic which verifies if the length of the string being returned, matches what I want it to be. I will be passing the string, i.e. social, and the limit, in this case 9. However, I can't seem to get the function to work properly. I get a Syntax error.
I need the StringLimit Variable to be Optional, as I may not need it all the time.
Here is the original function:
let intExtraction = (AlphaNumeric as any) => if AlphaNumeric = null then null else Number.From( Text.Combine( List.RemoveNulls( List.Transform( Text.ToList( // for values that come with dashes, else Excel will interpret as number if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric)), each if Value.Is(Value.FromText(_), type number) then _ else null ) ) )) in intExtraction
And here is what I've done so far (amont other things) to try to make it work.
let intExtraction = (AlphaNumeric as any, StringLimit as number) => let Integers = if AlphaNumeric = null then null else Number.From( Text.Combine( List.RemoveNulls( List.Transform( Text.ToList( // for values that come with dashes, else Excel will interpret as number if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric)), each if Value.Is(Value.FromText(_), type number) then _ else null ) ) ) ), LimitTest = if StringLimit = null then AlphaNumeric else if Text.Length(AlphaNumeric) <> StringLimit then null else AlphaNumeric in LimitTest
Solved! Go to Solution.
I was able to fix the error using syntax from other functions I've used in the past:
let intExtraction = (AlphaNumeric as any, optional StringLimit as number) => let Value = if AlphaNumeric = null then null else Number.From( Text.Combine( List.RemoveNulls( List.Transform( Text.ToList( // for values that come with dashes, else Excel will interpret as number if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric)), each if Value.Is(Value.FromText(_), type number) then _ else null ) ) ) ), CharLimit = if StringLimit = null then Value else if Text.Length(Number.ToText(Value)) <> StringLimit then null else Value in CharLimit in intExtraction
I was able to fix the error using syntax from other functions I've used in the past:
let intExtraction = (AlphaNumeric as any, optional StringLimit as number) => let Value = if AlphaNumeric = null then null else Number.From( Text.Combine( List.RemoveNulls( List.Transform( Text.ToList( // for values that come with dashes, else Excel will interpret as number if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric)), each if Value.Is(Value.FromText(_), type number) then _ else null ) ) ) ), CharLimit = if StringLimit = null then Value else if Text.Length(Number.ToText(Value)) <> StringLimit then null else Value in CharLimit in intExtraction
@Anonymous
It seems you need to check the if condition function.
Regards,
Cherie
Thanks @v-cherch-msft, I know that this is where the error is as it is the only addition made to the original, working version of the code.
The problem is, I don't know how to correctly fix this issue.
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.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |