Lambda Recursion Help

samdthompson

New Member
Joined
May 1, 2018
Messages
14
Hello, I have built a recursive Lambda which does not recurse. I cannot for the life of me work out which bit is going wrong other than the recursion. The main formula works well and manual recursion works exactly as it should. The aim is to remove "R" from the grid based on how many X's there are around them. The recursion should stop when there are no additional X's to remove. Note There may still be some X's left but not any that require removal.

Formula:
Excel Formula:
=_ValueRecusion(_rng,_initial_value)

Named Range:

Excel Formula:
=LAMBDA(_rng,_initial_value,
LET(
_up, OFFSET(_rng, -1, 0),
_right, OFFSET(_rng, 0, 1),
_down, OFFSET(_rng, 1, 0),
_left, OFFSET(_rng, 0, -1),
_x, MAP(_up, _right, _down, _left, LAMBDA(u,r,d,l, OR(u = "x", r = "x", d = "x", l = "x"))),
_txttosplit, _up & "," & _right & "," & _down & "," & _left, _txtsplit, LEN(_txttosplit) - LEN(SUBSTITUTE(_txttosplit, "R", "")),
_calc, IF(_rng = "W", "W", IF(_rng = "", "", IF(_x * _txtsplit = 1, "X", _rng))),
_current_count, COUNTA(FILTER(TOCOL(_calc), TOCOL(_calc) = "X")),
_finish, IF(_previous_count = _current_count, _calc, _ValueRecursion(_calc, _current_count)),
_finish)
)

Cheers
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I seem unable to edit the post so for clarity, two typos:

First =_ValueRecusion(_rng,_initial_value) should read =_ValueRecursion(_rng,_initial_value)
Second _finish, IF(_previous_count = _current_count, _calc, _ValueRecursion(_calc, _current_count)), should read IF(_initial_value = _current_count, _calc, _ValueRecursion(_calc, _current_count)),
 
Upvote 0
should read IF(_initial_value = _current_count ...
Thanks. That was an obvious problem with the formula as first posted.
This cannot be done as offset cant be used in recursion.
Says who?

It's a little hard to know what's going on without understanding your layout. Can you please post a 3x3 example that is not working, and let us know what result you're expecting the LAMBDA to return for this example.
 
Last edited:
Upvote 0
@samdthompson
A couple of forum issues to note:

1.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.
Be sure to follow & read the link at the end of the rule too!
Cross posted at: Recursion Help
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.
If you do cross-post in the future and also provide links, then there shouldn’t be a problem.

2.
I suggest that you update your forum profile (click your user name at the top right of the forum, then ‘Account details’) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
This cannot be done as offset cant be used in recursion.
The link you posted in the other forum has nothing to do with the LAMBDA function or recursion. The point being made was that OFFSET must refer to a cell/range.

The problem with your LAMBDA may be that you make the recursive call using _calc, which may not be a range.

But as I said before, it's hard to know without seeing your layout.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top