LAMBDA: ScheduleValuesλ

Description

Schedules values in a timeline from a schedule in a table.

Many models input values in each cell under a timeline which either never change, or change infrequently. This is tedious and error prone. Instead, enter only the dates that a value changes and the new value on that date, then use λScheduleValues to, using a dynamic array, place values for us. Need additional dates? Just add them to the table. Want to change a value or date? Just change the one record in the table.

Syntax

We see this LAMBDA being use in the GIF.:

=ScheduleValuesλ( <Timeline>, [<StartDates>], [<Values>] )

Where:

  • Timeline - The model's timeline range (works great with dynamic arrays too!)

  • StartDates - When a value starts. This can be an array of start dates or a table column devoted to rate scheduling. Whether array or table, start dates must be sorted in ascending order (this limitation will be changed when HSTACK() is generally available).

  • Values - Rates or amounts that start on the start dates and continue to the next start date (if any).

Code

This is the code as of this writing. This is a good example of our LAMBDAs can help beginners.

The formula in this LAMBDA is a fairly simple. Those with intermediate Excel skills may prefer typing XLOOKUP() instead of this LAMBDA. But for those starting out, this LAMBDA takes a generic function (XLOOKUP) and, by the LAMBDA's name, communicates its use. So when someone with limited experience searches for a function to schedule rates, when they see this LAMBDA's name, they will know it applies to their need. When the see XLOOKUP, they may not connect that name with this purpose and instead of scheduling amounts, they fall back on typing them in by hand and suffer the tedium and, potentially, associated errors.

I intend to update this when Microsoft implements HSTACK. So for the most current version, see the Gist.

/*

FUNCTION NAME: ScheduleValuesλ

DESCRIPTION: Schedules values in a timeline from a schedule in a table.

EXAMPLE: =λScheduleValues(Timeline, tblRates(Start), tblRates(Values))

Many models have manually entered values in each cell under a timeline

which either never change, or change infrequently. This is tedious and

error prone. Instead, enter only the dates that a value changes and the

new value on that date, then use ScheduleValuesλ to, using a dynamic array,

place values for us.

Need additional dates? Just add them to the table.

Want to change a value or date? Just change it in the table.


ARGS:

Timeline An horizontal range or dynamic array holding the model's timeline

Starts A table column or array of dates when values take effect

Values Table column or array of values that change with dates


GUILTY PARTIES: Craig Hatmaker 2022

*/

ScheduleValuesλ = LAMBDA(

// Parameter Declarations

Timeline,

Starts,

Values,


// Function starts here

XLOOKUP(Timeline, Starts, Values, "", -1)

);

Importing

Use the Advance Formula Environment add-in available (free) from the Microsoft store (use Developer tab > Add-ins icon > This LAMBDA is available for download. Click Advanced Formula Environment to learn more about that.

All of my LAMBDAs can be found here: https://gist.github.com/CHatmaker.

This specific LAMBDA is part of a Dates library at this URL:

https://gist.github.com/CHatmaker/3e1708888ec2bd1cde2ec9d002dc459b