Last active
August 18, 2025 01:36
-
-
Save CHatmaker/3e6cba6414fadfabfa3725255da2ba74 to your computer and use it in GitHub Desktop.
BXL 5g Functions LAMBDA Modeling Templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Base Template | |
| /* FUNCTION NAME: <enter name here>λ | |
| DESCRIPTION:*//**<this comment displays in name manager>*/ | |
| /* REVISIONS: Date Developer Description | |
| <changed> <your name> <what changed> | |
| */ | |
| BaseTemplateλ = LAMBDA( | |
| // Parameter Declarations | |
| [Argument1], // All arguments must have [ ] | |
| [Argument2], // Add as many arguments as needed. | |
| [Argument3], | |
| // Help | |
| LET(Help, TRIM(TEXTSPLIT( | |
| "FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
| "DESCRIPTION: →Copy description from comment block at top.¶" & | |
| "WEBPAGE: →URL¶" & | |
| "VERSION: →copy date from last revision in REVISIONS¶" & | |
| "PARAMETERS: →¶" & | |
| "Argument1 →(Required) Description of required argument1¶" & | |
| "Argument2 →(Required) Description of required argument2¶" & | |
| "Argument3 →(Optional) Description of optional argument3 with what default is¶" & | |
| "EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
| "→=ID.FunctionNameλ( 123, 456)", | |
| "→", "¶" ) | |
| ), | |
| // Check inputs - Omitted required arguments (do not include optional arguments) | |
| Help?, OR( ISOMITTED( Argument1), | |
| ISOMITTED( Argument2 ) | |
| ), | |
| // Set internal named constants if needed | |
| // Set defaults for optional arguments if needed | |
| Argument3, IF( ISOMITTED( Argument3), 0, Argument3), | |
| // Procedure starts here | |
| Result, Argument1 + Argument2 - Argument3, // Last Formula line goes here | |
| // Return Result | |
| CHOOSE(Help? + 1, Result, Help) | |
| ) | |
| ); | |
| // Corkscrew Template | |
| /* FUNCTION NAME: <enter name here>λ | |
| DESCRIPTION:*//**<this comment displays in name manager>*/ | |
| /* REVISIONS: Date Developer Description | |
| <changed> <your name> <what changed> | |
| */ | |
| Corkscrewλ = LAMBDA( //Change this name | |
| // Function Arguments | |
| [Opening], | |
| [Gains], //Set arguments as needed | |
| [Losses], | |
| // Help | |
| LET(Help, TRIM(TEXTSPLIT( | |
| "FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
| "DESCRIPTION: →Copy description from comment block at top.¶" & | |
| "WEBPAGE: →URL¶" & | |
| "VERSION: →copy date from last revision in REVISIONS¶" & | |
| "PARAMETERS: →¶" & | |
| "Argument1 →(Required) Description of required argument1¶" & | |
| "Argument2 →(Required) Description of required argument2¶" & | |
| "Argument3 →(Optional) Description of optional argument3 with what default is¶" & | |
| "EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
| "→=ID.FunctionNameλ( 123, 456)", | |
| "→", "¶" ) | |
| ), | |
| // Check inputs - Omitted required arguments (do not include optional arguments) | |
| Help?, OR( ISOMITTED( Argument1), //In this example, Argument1 is an opening balance | |
| ISOMITTED( Argument2 ) //In this example, Argument2 is an array to be processed | |
| ), | |
| // Pre calcs | |
| Flows, Gains - Losses, //Change as needed | |
| // Calculations | |
| CLose, SCAN( Opening, Flows, SUM), //Calculate Close | |
| Open, HSTACK( Opening, DROP( Close, , -1)), //Create Open | |
| Result, VSTACK( Opening, Gains, Losses, Close), //Stack rows | |
| // Return Result | |
| IF( Help?, Help, Result) | |
| ) // Close LAMBDA's LET | |
| ); // Close LAMBDA | |
| // REDUCE and STACK Template | |
| /* FUNCTION NAME: <enter name here>λ | |
| DESCRIPTION:*//**<this comment displays in name manager>*/ | |
| /* REVISIONS: Date Developer Description | |
| <changed> <your name> <what changed> | |
| */ | |
| ReduceAndStackλ = LAMBDA( //Change this name | |
| // Function Arguments | |
| [Opening], // All arguments must have [ ] - For this template assume this is the opening amount | |
| [Array#1], // Add as many arguments as needed. Not all need to be arrays. | |
| [Array#2], | |
| // Help | |
| LET(Help, TRIM(TEXTSPLIT( | |
| "FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
| "DESCRIPTION: →Copy description from comment block at top.¶" & | |
| "WEBPAGE: →URL¶" & | |
| "VERSION: →copy date from last revision in REVISIONS¶" & | |
| "PARAMETERS: →¶" & | |
| "Opening →(Required) Opening Balance¶" & | |
| "Array1 →(Required) Description of required argument2¶" & | |
| "Array2 →(Optional) Description of optional argument3 with what default is¶" & | |
| "EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
| "→=ID.FunctionNameλ( 123, 456)", | |
| "→", "¶" ) | |
| ), | |
| // Check inputs - Omitted required arguments (do not include optional arguments) | |
| Help?, OR( ISOMITTED( Opening), //In this example, an opening balance | |
| ISOMITTED( Array1) //In this example, Argument2 is an array to be processed | |
| ), | |
| // Set internal named constants if needed | |
| // Set defaults for optional arguments if needed | |
| Array2, IF( ISOMITTED( Array2), <fill in default>, Array2), | |
| // Calculate things that only need to be calculated once here | |
| Columns, COLUMNS( <Array1>), | |
| Periods, SEQUENCE( , Columns), | |
| // Procedure | |
| // Process each column | |
| Result, REDUCE( Opening, Periods, | |
| LAMBDA( Acc, Period, | |
| LET( | |
| // Get Opening Balance | |
| Open, TAKE( Acc, -1, -1), | |
| // Get current period's values | |
| Value1, INDEX( Array1, Period), | |
| Value2, INDEX( Array2, Period), | |
| // Calculate close | |
| Close, Open + Value1 - Value2 // Change as needed | |
| // Vertically stack values into a column | |
| Stack, VSTACK( Open, Value1, Value2, Close), // Change as needed | |
| // Horizontally stack columns together | |
| Result, IF( Period = 1, Stack, HSTACK( Acc, Stack)), | |
| // Return REDUCE's Result | |
| Result | |
| ) // Close REDUCE's LAMBDA's LET | |
| ) // Close REDUCE's LAMBDA | |
| ), // Close REDUCE | |
| IF( Help?, Help, Result) | |
| ) // Close LET | |
| ); // Close LAMBDA | |
| // Circularity Template | |
| /* FUNCTION NAME: <enter name here>λ | |
| DESCRIPTION:*//**<this comment displays in name manager>*/ | |
| /* REVISIONS: Date Developer Description | |
| <changed> <your name> <what changed> | |
| */ | |
| AverageBalanceInterestλ = LAMBDA( //Change this name | |
| // Parameter Declarations | |
| [CashBeforeInt], // Add as many arguments as needed. | |
| [BeginningDebt], // All arguments must have [ ] | |
| [InterestRate], // Change these names to suit | |
| // Help | |
| LET(Help, TRIM(TEXTSPLIT( | |
| "FUNCTION: →FunctionNameλ( Argument1, Argument2, [Argument3])¶" & | |
| "DESCRIPTION: →Copy description from comment block at top.¶" & | |
| "WEBPAGE: →URL¶" & | |
| "VERSION: →copy date from last revision in REVISIONS¶" & | |
| "PARAMETERS: →¶" & | |
| "Argument1 →(Required) Description of required argument1¶" & | |
| "Argument2 →(Required) Description of required argument2¶" & | |
| "Argument3 →(Optional) Description of optional argument3 with what default is¶" & | |
| "EXAMPLES: →Formula (ID is assumed to be the module's name)¶" & | |
| "→=ID.FunctionNameλ( 123, 456)", | |
| "→", "¶" ) | |
| ), | |
| // Check inputs - Omitted required arguments (do not include optional arguments) | |
| Help?, OR( ISOMITTED( CashBeforeInt), //Change this to match argument 1's name | |
| ISOMITTED( BeginningDebt), //Change this to match argument 2's name | |
| ISOMITTED( InterestRate ) //Change this to match argument 3's name | |
| ), | |
| // Set internal named constants if needed | |
| // Set defaults for optional arguments if needed | |
| // Iterative function definition (fn) - Change the parameters and LET() statement to suit | |
| Iterate, LAMBDA( fn, CashBeforeInt, BeginningDebt, InterestRate, AverageDebt, | |
| LET(Interest, AverageDebt * InterestRate, | |
| CFADS, CashBeforeInt - Interest, | |
| EndingDebt, BeginningDebt - CFADS, | |
| AverageDebt, Average( BeginningDebt, EndingDebt), | |
| Delta, ABS( Interest - (AverageDebt * InterestRate)), | |
| Result, IF( Delta < 0.01, | |
| Interest, | |
| fn( fn, | |
| CashBeforeInt, BeginningDebt, InterestRate, AverageDebt | |
| ) | |
| ), | |
| Result | |
| ) | |
| ), | |
| // Procedure - Change parameters to suit | |
| Result, Iterate( Iterate, CashBeforeInt, BeginningDebt, InterestRate, 0), | |
| // Return result or Help | |
| CHOOSE( Help? + 1, Result, Help) | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment