English

The TIMESUM function aggregates values between two time periods and returns a single value.

For example, you can use the TIMESUM function to aggregate the revenue for previous periods through to the current period.

TIMESUM(Line item to aggregate [, Start period] [, End period] [, Aggregation method])

Arguments

Argument Data type Description
Line item to aggregate(required)

Number, Boolean, date, list, or text

This argument must be a line item.

The line item to aggregate over a period of time.

This line item must have Time as a dimension.

Start period Number, date, time period

The period to start the aggregation from. This period is included in the aggregation.

If omitted, the function aggregates all periods.

End period Number, date, time period

The end period to finish the aggregation at. This period is included in the aggregation.

If omitted, the function only returns the value for the period in theStart periodargument.

Aggregation method Keyword

The aggregation method to use.

The available keywords are SUM, AVERAGE, MIN, MAX, ANY, ALL, FIRSTNONBLANK, LASTNONBLANK, and TEXTLIST. There's more information below.

The default behavior if omitted depends upon the data type of theLine item to aggregateargument.

The TIMESUM function returns a result of the same data type as theLine item to aggregateargument.

Aggregation method keywords

Keyword Compatible data types Description
SUM Number Returns the sum of the values.
AVERAGE Number Returns the mean average of the values.
MIN Number, date

For numbers, returns the lowest value.

For dates, returns the earliest value (a blank cell is considered to be as early as possible).

MAX Number, date

For numbers, returns the highest value.

For dates, returns the latest possible date.

ANY Boolean Returns a value of TRUE if any values of a Boolean-formatted line item are TRUE.
ALL Boolean Returns a value of TRUE if all values of a Boolean-formatted line item are TRUE.
FIRSTNONBLANK Number, date, list, or text Returns the first non-blank value for all data types.
LASTNONBLANK Number, date, list, or text Returns the last non-blank value for all data types.
TEXTLIST Text Returns all of the values of a text-formatted line item, separated by a comma and a space.

Syntax example

TIMESUM(Revenue, -2, 0, SUM)

This formula sums the values for theRevenueline item from two periods before the current period through to the current period. This is inclusive of the start and end period.

Additional information

Default aggregation method

The default aggregation method used when you omit theAggregation methodargument varies based on the data type of theLine item to aggregateargument. If the data type of theLine item to aggregateargument is:

  • Number, the default behavior is to SUM.
  • Boolean, the default behavior is ANY.
  • Date, list, or text, the default behavior is FIRSTNONBLANK.

Optimize module performance with TIMESUM

TheStart periodandEnd periodarguments for the TIMESUM function define the period to aggregate values over. The TIMESUM function only returns a single value, the aggregated value over this defined range of periods. As a result, it's best to use the TIMESUM in a line item without theTimedimension to optimize module performance.

Different data types for start and end period

UseStart periodandEnd periodarguments with number, date, or time period data type values. You can use different data types for each argument.

For example, you can specify a time period for theStart periodargument, and 0 for theEnd periodargument. This aggregates values between the specified time period and the current period and updates automatically as the current period changes.

Constraints

  • TheLine item to aggregateargument must have Time as a dimension.
  • You must define aCurrent PeriodinModel Settingsto use a number value for theStart periodorEnd periodarguments.
  • If you use a date value for either theStart periodorEnd periodargument, their positions are swapped. This means that theEnd periodargument should be a date in the period when aggregation begins andStart periodshould a the date in the period when aggregation ends.

Calculation engine functionality differences

In Polaris:

  • You can only use a number for theLine item to aggregateargument.
  • If you only provide a value for theStart periodargument and not theEnd periodargument, the TIMESUM function aggregates all values from theStart periodthrough to the end of the applicable time range.
  • When you use date values for theStart periodandEnd periodarguments, they behave as expected.
  • IfStart periodorEnd periodare outside the range of the time dimension, then TIMESUM returns 0.

In the Classic Engine:

  • You can use a value with a data type of number, Boolean, date, list, or text for theLine item to aggregateargument.
  • If you only provide a value for theStart periodargument and not theEnd periodargument, the TIMESUM function returns the value from theStart period.
  • When you use date values for theStart periodandEnd periodarguments, the behavior is inverted. This means that the date for theStart periodshould be in the period where aggregation ends and the date for theEnd periodshould be in the period where aggregation begins.

Examples

Start period and End period arguments

In this example, there are two modules. The first module contains theTimedimension on columns, and theRevenueline item on rows. The module is namedRevenue 2021, which is referenced in later formulas.

TheCurrent Periodin this model, as defined inModel Settings > Time, isMay 21.


Jan 21 Feb 21 Mar 21 Apr 21 May 21 Jun 21 Jul 21 Aug 21 Sep 21 Oct 21 Nov 21 Dec 21
Revenue 101,480 130,156 117,021 122,556 123,160 143,432 130,784 134,415 115,309 117,279 128,835 108,029

The second module contains only line items, which each contain formulas. These formulas highlight how you can use theStart periodandEnd periodargument to specify the period of aggregation.

The reason the formulas are in a separate module is because you should use TIMESUM in a module without theTimedimension to optimize performance.

Revenue for all periods

TIMESUM(Revenue 2021.Revenue)

1,472,456

Revenue for 2 months ago

TIMESUM(Revenue 2021.Revenue, -2)

117,021

Revenue from 2 months ago to current period

TIMESUM(Revenue 2021.Revenue, -2, 0)

362,737

Revenue for duration of Spring campaign

TIMESUM(Revenue 2021.Revenue, TIME.'Jan 21', TIME.'Apr 21')

471,213

Example with only Line item to aggregate argument

The first formula, in theRevenue for all periodsline item, uses only theRevenueline item for theLine item to aggregateargument. This means that the formula uses the default behavior for TIMESUM and sums all values in the module. This behavior can be useful when you useWeeks: GeneralinModel Settings > Time, as thisCalendar Typedoes not contain a summary of all periods.

Example with Start period argument

The second formula, in theRevenue for 2 months agoline item, uses theRevenueline item for theLine item to aggregateargument. The formula uses-2for theStart periodargument. This means that the formula returns only the value from the period two periods before theCurrent Period, May 21. In this case, this is the value 117,021 from Mar 21.

In Polaris, this formula would aggregate all values from and including Mar 21 until the last period in the applicable time range.

Example with Start period and End period argument

The third formula, in theRevenue from 2 months ago to current periodline item, uses theRevenueline item for theLine item to aggregateargument. The formula uses-2for theStart periodargument and0for theEnd periodargument. This means that the formula sums the values from two periods before the current period, through to the current period. In this case, this is 362,737, the sum of the values for Mar 21, Apr 21, and May 21.

Example with references to Time dimension

The fourth formula, in theRevenue for duration of Spring campaignline item, uses theRevenueline item for theLine item to aggregateargument. The formula uses references to theTimedimension for theStart periodandEnd periodarguments.Time.'Jan 21'andTime.'Apr 21'respectively. This means that the formula sums the values of theRevenueline item for and between these periods. As the formula uses references to theTimedimension, the values for the formula do not change as the current period in theModel Calendarchanges.

Examples of different Aggregation methods

In this example, there are two modules. The first module contains theTimedimension on columns, and a number of line items on rows. The module is namedInitiative KPIs 2021, which is referenced in later formulas.

TheCurrent Periodin this model, as defined inModel Settings > Time, is Dec 21.


Jan 21 Feb 21 Mar 21 Apr 21 May 21 Jun 21 Jul 21 Aug 21 Sep 21 Oct 21 Nov 21 Dec 21
Revenue 101,480 130,156 117,021 122,556 123,160 143,432 130,784 134,415 115,309 117,279 128,835 108,029
Promotion Active?




New product release date

3/24/2021 4/30/2021

7/14/2021

/10/15/2021 11/1/2021
Product name

Apple pie Cinnamon swirl

Sugar donut

Lemon meringue pie Mille-feuille

The second module contains only line items, which each contain formulas. These formulas highlight the behavior of the different keywords for theAggregation methodargument. Each formula uses aStart periodof-2andEnd periodof0. This means that they apply to the values forOct 21,Nov 21, andDec 21.

The reason the formulas are in a separate module is because you should use TIMESUM in a module without theTimedimension to optimize performance.

Total revenue for last 3 months

TIMESUM(Initiative KPIS 2021.Revenue, -2, 0, SUM)

354,143

Average revenue for last 3 months

TIMESUM(Initiative KPIS 2021.Revenue, -2, 0, AVERAGE)

118,048

Lowest revenue for last 3 months

TIMESUM(Initiative KPIS 2021.Revenue, -2, 0, MIN)

108,029

Highest revenue for last 3 months

TIMESUM(Initiative KPIS 2021.Revenue, -2, 0, MAX)

128,835

Promotion active last 3 months?

TIMESUM(Initiative KPIS 2021.Promotion active?, -2, 0, ANY)

Promotion active for entirety of last 3 months?

TIMESUM(Initiative KPIS 2021.Promotion active?, -2, 0, ALL)


First product release date in last 3 months

TIMESUM(Initiative KPIS 2021.New product release date, -2, 0, FIRSTNONBLANK)

10/15/2021

Last product release in last 3 months

TIMESUM(Initiative KPIS 2021.New product release date, -2, 0, LASTNONBLANK)

11/1/2021

Names of products released in last 3 months

TIMESUM(Initiative KPIS 2021.Product name, -2, 0, TEXTLIST)

Lemon meringue pie, Mille-feuille

Numeric aggregation method examples

前四行项目包含德公式monstrate the behavior of the SUM, AVERAGE, MIN, and MAX keywords respectively. These aggregation methods can only be used with number-formatted values. For the values of Oct 21, Nov 21, and Dec 21, which are 117,279, 128,835, and 108,029, the formulas:

  • Sum each of the three values for a total of 354,143.
  • Return the mean average of the three values, 118,048.
  • Return the lowest value of the three, 108,029.
  • Return the highest value of the three, 128,835.

Boolean aggregation method examples

The fifth and sixth line items contain formulas that demonstrate the behavior of the ANY and ALL keywords respectively. These aggregation methods can only be used with Boolean-formatted values. For the values of Oct 21, Nov 21, and Dec 21, the formulas:

  • Check if any of the Boolean values are TRUE. As two of three are, it returns a value of TRUE.
  • Check if all of the Boolean values are TRUE. As only two of three are, it returns a value of FALSE.

FIRSTNONBLANK and LASTNONBLANK keyword examples

The seventh and eight line items contain formulas that demonstrate the behavior of the FIRSTNONBLANK and LASTNONBLANK keywords respectively. These aggregation methods can be used with number-, date-, list-, or text-formatted values. In this case, the line items contain dates that represent product release dates. For the values of Oct 21, Nov 21, and Dec 21, the formulas:

  • Return the first non-blank date-formatted value, 10/15/2021.
  • 返回最后一个非空date-formatted价值,11/1/2021.

TEXTLIST keyword example

第九行项目包含一个公式,恶魔trates the behavior of the TEXTLIST keyword. This aggregation method can only be used with text-formatted values. The formula concatenates the values of Oct 21, Nov 21, and Dec 21, separating each value with a comma. It returnsLemon meringue pie, Mille-feuille.

Disclaimer

We update Anapedia content regularly to provide the most up-to-date instructions.