LAMBDA: SumPeriodλ

Description

Returns a two dimensional array of totals for each item and each period.

Use this to aggregated our model's results into larger periods.

Syntax

We see this LAMBDA being use in the GIF.:

=SumPeriodλ( <Values>, <Dates>, <PeriodStart>, <PeriodEnd> )

Where:

  • Values- A two dimensional array of values to be aggregated.

  • Dates- The Values array's timeline

  • PeriodStart- A timeline of period start dates which govern the values to aggregate into this period

  • PeriodEnd- A timeline of period end dates which govern the values to aggregate into this period

Code

This is the code as of this writing. For the most current version, see the Gist.

/*

FUNCTION NAME: SumPeriodλ

DESCRIPTION: Returns a vector array of totals by row for values between (inclusive) dates


This was developed for budgeting where we have expenses that start, and

sometimes repeat at regular intervals.

EXAMPLE: =SumPeriodλ(daValues, daDates, daPeriodStart, daPeriodEnd)

For more on this see: https://sites.google.com/site/beyondexcel/home/excel-library/lambda-sumperiod%CE%BB

ARGS:

Values A two dimensional array of values where each column is for a specific day

Dates A one dimensional array of dates that apply to each column in Values

PeriodStart A one dimensional array of dates denoting the start of a period to total Values by

PeriodEnd A one dimensional array of dates denoting the End of a period to total Values by


Copyright: Craig Hatmaker 2022 - Anyone may use but not claim ownership or authorship

*/


SumPeriodλ = LAMBDA(

// Parameter Declarations

Values,

Dates,

PeriodStart,

PeriodEnd,


// Function starts here

LET(

// Determine # of array rows

Rows, SEQUENCE(ROWS(Values), , 0),


// Function starts here

SUMIFS(

OFFSET(Values, Rows, 0, 1),

Dates, ">=" & PeriodStart,

Dates, "<=" & PeriodEnd

)

)

);

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