Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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.
User | Count |
---|---|
97 | |
87 | |
77 | |
67 | |
63 |
User | Count |
---|---|
111 | |
96 | |
96 | |
67 | |
63 |