distribute - Value Distribution over Timeline

Prev Next

Function Names

distribute, distribute advance

Description

This function distributes a value over a time line of intervals such as days, weeks, months, quarters and years. Either a fixed total value is distributed between two specified dates, or a combination of start date and capacity (unit per day) is provided and the end date will be calculated automatically (e.g. Total value = 10, capacity per day = 2 means 5 days).

Doing a production planning with production start date, production end date and number of items to produce is a good example.
If a batch size is given (e.g. 10 items produced at a time), then specify it.
If the distribution should not be bound to deliveries, but to purchasing / receiving required material for these items, then use the function distribute advance.

Alternative to total value, the softqutoed string '#days' (use no or single quoatation marks, but not double quotation marks) can be specified instead of the total value in order to return the number of days instead. Note regarding dates: Dates are always considered as plain dates, ignoring time of day info if contained in the date values.

Detailed overview with many examples: See available PDF overview

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

10-14

Parameters

No.TypeDescription
1
input
numerals or strings Total value

Total value to be distributed over the timeline.
Alternatively, specify #days (only this string value is allowed here), sot the total value will relate to the total number of identified work days.

2
input
numeral Batch size

The batch size must be 0 or a positive value.
0 = No subsivision. The total value will be distributed proportionally across the periods.
1 = Batch size of 1 unit.
The bach size must not necessarily be an integer. Choosing 0.5 is valid and would rule batch sizes of half items.

3
input
date or string converted to date Start date

Must provide a valid date. Any time of day info will be ignored.

4
input
date or string converted to date End date

Must provide a valid date which must be after the start date or at the same day. Any time of day info will be ignored.

Alt. 4
input
numeral Capacity per day

Instead of specifying an end date, you an also specify a capacity value in units per day. The end date will be calculated automatically.

5
input
string Intervals

This parameter determinse if you want to do a plan on daily, weekly, monthly or other basis. Note that a daily planning is the most fine-grained option and produces the biggest and most detailed plans.

Intervals parameter Description
days Distribution over days
weeks Distribution over weeks
whole weeks Distribution over weeks, all weeks are considered as full weeks (even if start and/or end dates lie in the middle of the weeks)
months Distribution over months
whole months Distribution over months, all months are considered full months (even if start and/or end dates lie in the middle of the months)
quarters Distribution over quarters
whole quarters Distribution over months, all quarters are considered full quarters (even if start and/or end dates lie in the middle of the quarters)
quarters whole months Distribution over quarters, full months are considered if start and/or end dates are in the middle of the quarters)
years Distribution over years
whole years Distribution over years, all years are considered full years (even if start and/or end dates lie in the middle of the years)
years whole months Distribution over years, full months are considered if start and/or end dates are in the middle of the years)
years whole quarters Distribution over years, fullquarters are considered if start and/or end dates are in the middle of the years)

6
input
string Usance

Usance is a work and trade practice parameter which is used in association with the 5th function parameter Intervals.

Usance Parameter Description
calendar Based on 365/366 days per year calendar, 7 days per week work time. Respects bank and school holidays (vacation days) if specified.
mon_fri Based on 365/366 days per year calendar, 5 days per week work time (Mondays through Fridays). Respects bank and school holidays (vacation days) if specified.
mon_sat Based on 365/366 days per year calendar, 6 days per week work time (Mondays through Saturdays). Respects bank and school holidays (vacation days)if specified.
30_360 Rules all months having 30 days and all years having 360 days. Common in finance. Ignores bank and school holidays (vacation days) if specified.
Only valid in combination with following Intervals: months, whole months, quarters, whole quarters, years, whole years.

7
input
date or string converted to date Output Start date

This value specifies the starting date for the output to generate. If 5th parameter is not 'days', then the date will be moved back to the begin of the chosen interval (weeks, months, quarters, years). E.g. if '31.05.2017' is specified for months, then the whole month of May will be considered.

8
input
date or string converted to date Output End date

This value specifies the ending date for the output to generate. If 5th parameter is not 'days', then the date will be moved forward to the end of the chosen interval (weeks, months, quarters, years). E.g. if '01.05.2017' is specified for months, then the whole month May will be considered.

9
output
parameter set containing dates Timeline Start Dates

Parameter set containing dates related to the values returned in the next parameter (Distributed values). If interval other than days is specified, then the starting date of the week/month/etc... will be returned.

10
output
parameter set containing numerals Distributed Values

Actual result: Total values distributed over the specified timeline

Opt. 11
output
numeral Earlier Sum

Non-zero if distributed values exist before the output start date specified in order not to miss them.

Opt. 12
output
numeral Later Sum

Non-zero if distributed values exist after the output end date specified in order not to miss them.

Opt. 13
input
parameter set containing dates Bank Holidays

A set of dates may be supplied to declare specific days as bank holidays so these days will not be counted. This parameter is rejected if the Usance '30_360' is chosen. The dates may be provided as data type date or string containing legitimate dates. Type conversion to dates takes place automatically.

Use the year 1900 (lies well in the past and this is good so) in order to declare bank holidays as anually repeating bank holidays. Example: "1900-07-14" declares French national holiday for every year.

Default value: {} (Empty set)
Opt. 13
input
parameter set containing dates School Holidays

A set of dates may be supplied to declare school holidays (vacation days). This parameter is rejected if the Usance '30_360' is chosen. The dates may be provided as data type date or string containing legitimate dates. Type conversion to dates takes place automatically. An even number of dates must be specified as the first date describes the first vacation day and the next date describes the last vacation day.

Use the year 1900 (lies well in the past and this is good so) in order to declare school holidays (vacation) as anually repeating events.
Example: "1900-07-01", "1900-07-21" declares the first 3 weeks of every July as vacation.

Default value: {} (Empty set)

Return value

TypeDescription
boolean Total value fully distributed

true if the total value has been fully distributed between output start and output end date and optionally to the output values Earlier Sum and Later Sum.

Exceptions

Division by zero error happens if WACC equals to the perpetual growth rate

Examples

      distribute( #days, 0, '06.01.2018', '25.01.2018', days, calendar, '01.01.2018','31.01.2018', date line[], distributed values[] );
      echo( date line[]{0},", ", date line[]{1},", ", date line[]{2},", ", date line[]{date line[]{}-1} );
      echo( join( distributed values[], ", " ) );

Output

2018-01-01, 2018-01-02, 2018-01-03, 2018-01-31
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
Try it yourself: Open LIB_Function_distribute.b4p in B4P_Examples.zip. Decompress before use.

See also

table distribute