+ Reply to Thread
Results 1 to 19 of 19

Recursive lambda

  1. #1
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,625

    Recursive lambda

    JeteMc answered the original Q. GregB11 made the first O365-type formula:

    https://www.excelforum.com/excel-for...ml#post5919354



    I took it to the next stage. However, as I said in the thread, my brain only works in straight lines. I can't do recursive lambdas. The original post referred to thousands of staff memebrs and 15 reporting levels. Can anyone out there see how to calculate the number of direct and indirect reportees under each staff member with a recursive lambda, or similar, thus avoiding the need for 15 of these????

    Level2,FILTER(a,ISNUMBER(MATCH(b,Level1,0)),"")
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  2. #2
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    The formula looks for the number of indirect calls, 1 level further. (Indirect, indirect calls are not counted).
    For that reason, a regular iterative formula can also be found that calculates this.

    This formula (available in O365 V2401 or newer) returns the same results, but sorted by manager name:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    Oops, without realizing it I changed Glenn's formula just a little bit, so indirect indirect calls were no longer counted.
    I'm sorry Glenn.

    Glenn's original formula also counts indirect indirect calls.

    Therefore, ignore my previous post.

    I'll think about a recursive lambda tomorrow.

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    I haven't been able to come up with a recursive lambda for this problem.

    I did come up with another iterative solution, which can very easily be adjusted to the maximum number of levels.

    This example assumes a maximum of 6 levels.
    With more or fewer levels, only the red part of the formula needs to be adjusted.

    Please define in the Name Manager ic:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and try this formula:
    Please Login or Register  to view this content.
    This formula uses GROUPBY (available in O365 V2401 or newer)
    Attached Files Attached Files
    Last edited by HansDouwe; 02-12-2024 at 03:45 AM.

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,625

    Re: Recursive lambda

    Hahaha. Lovely. And wayyy beyond my pay grade. I just don't follow what ic is doing. I DO only think in straight lines.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,625

    Re: Recursive lambda

    Of course, I can't resist the temptation to tweak the bit I do understand to keep everyone in hierarchical order:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Recursive lambda

    Quote Originally Posted by HansDouwe View Post
    This formula uses GROUPBY (available in O365 V2401 or newer)
    No GROUPBY
    O365 V2401 here...

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,625

    Re: Recursive lambda

    I think it is 2402

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,368

    Re: Recursive lambda

    I don't know what this will be like with a large dataset and many more levels, but seems ok with the sample. I'm pretty sure it could be tidier though!

    Lambda named CountSubs:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The output formula then becomes:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Sample attached.
    Attached Files Attached Files
    Everyone who confuses correlation and causation ends up dead.

  10. #10
    Forum Contributor John Vergara's Avatar
    Join Date
    01-17-2022
    Location
    Colombia
    MS-Off Ver
    365
    Posts
    201

    Re: Recursive lambda

    Hi everyone!

    Check this formula with recursion. Blessings!
    Attached Files Attached Files
    A out-of-context text is a pretext.
    Consider adding reputation points to all the people who help you with your question/problem.

  11. #11
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    Quote Originally Posted by rorya View Post

    Lambda named CountSubs:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Nice real recursive solution Rory. I will study your solution.

  12. #12
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    Quote Originally Posted by John Vergara View Post
    Check this formula with recursion.
    I've checked your formula John, but I don't see recursion.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,368

    Re: Recursive lambda

    Thank you Hans - appreciate that!

    The LAMBDA defined for f in John's formula appears to be recursive?

  14. #14
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    Quote Originally Posted by Glenn Kennedy View Post
    what ic is doing?
    Thanks for the feedback and rep. Glenn. .


    From a list of people, ic looks for other people who have called one of them and adds them to the list.
    Ic is called the first time with the manager for which you want to know the number of indirect calls.
    And after the last call, ic returns everyone who called the manager directly or indirectly.

  15. #15
    Forum Contributor John Vergara's Avatar
    Join Date
    01-17-2022
    Location
    Colombia
    MS-Off Ver
    365
    Posts
    201

    Re: Recursive lambda

    Quote Originally Posted by HansDouwe View Post
    I've checked your formula John, but I don't see recursion.
    Yes Hans, the formula is recursive, only it does not need name generation (inside the formula it calls itself).
    Quote Originally Posted by rorya View Post
    The LAMBDA defined for f in John's formula appears to be recursive?
    Yes rorya, it is.

    With Rorya's excellent proposal, I have designed a new recursive function, removing unnecessary variables within it. Check the attachment, blessings!
    Attached Files Attached Files

  16. #16
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: Recursive lambda

    Quote Originally Posted by John Vergara View Post
    Inside the formula it calls itself.
    Thank you John.
    I didn't know that was possible outside the name manager.
    I keep learning things about Excel here.
    It makes sense for me to study this carefully.

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,492

    Re: Recursive lambda

    When you've studied it, can you teach the rest of us?

    Always things to learn - every day is a lesson.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  18. #18
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,368

    Re: Recursive lambda

    Mynda has a write up of that 'inline' lambda approach here: https://www.myonlinetraininghub.com/...mbda-functions

    It's definitely an easier way to develop and debug than the name manager!

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,492

    Re: Recursive lambda

    Thanks, Rory.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Match and Extract -LAMBDA,MAP,FILTER
    By paradise2sr in forum Excel Formulas & Functions
    Replies: 32
    Last Post: 02-02-2024, 04:55 AM
  2. Need help getting LAMBDA to work
    By Newtonus_Prime in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-21-2023, 09:15 AM
  3. [SOLVED] Using TEXTSPLIT with MAP and LAMBDA is not working
    By Jacc in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-17-2023, 03:15 PM
  4. [SOLVED] Bisectional method using recursive Lambda
    By Jacc in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 09-07-2023, 05:19 PM
  5. [SOLVED] Maximum Drawdown and LAMBDA
    By andrewc in forum Excel General
    Replies: 5
    Last Post: 06-28-2023, 09:25 AM
  6. [SOLVED] LAMBDA iteration
    By Slabu in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-20-2021, 08:39 PM
  7. Lambda Expressions in Excel VBA
    By Gregor y in forum Tips and Tutorials
    Replies: 4
    Last Post: 10-17-2014, 06:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1