An example of a recursive function in Power Query: I'm looping through all the numbers in a text string and adding them together.
There are two "tricks" to recursion:
1) Start out with your break-out condition. In my case, I want to stop when my looper is 0, because I've gone through all the numbers in my text-string
2) Make sure that when you recursively call the function, you have to change your looper - either increase or decrease it. In my case, I go through one character at a time and I move to the left, so I do looper minus 1
Other than that, you call the function using "+ @NameOfFunction(argument1)"
If you actually have to do this in real life, I'd instead split the only-numbers text string into a list using Text.Split, then using List.Sum, i.e.
1) Text.Select(myText1, {"0" .. "9"})
2) Text.ToList(myText2)
The list is a list of text, not list of numbers. We need type conversion first
3) List.Transform(myText3, each Number.From(_))
4) List.Sum(myText4)
00:00 Example of recursion
01:37 Logic of the function
01:50 Remove non-numbers
02:30 Length of only-numbers
03:15 Recursive loop through my text
06:16 My function has two arguments!
07:38 Adding the last step
08:52 Summary
Негізгі бет 75 - Recursion in Power Query
Пікірлер: 1