Skip to main content

atoti.date_shift(measure, on, /, *, offset, dense=False, fallback=None)

Return a measure equal to the passed measure shifted to another date.
  • Parameters:
    • measure (VariableMeasureConvertible) – The measure to shift.
    • on (Hierarchy) – The hierarchy to shift on. Only hierarchies with their last level with a data_type of "LocalDate" or "LocalDateTime" are supported.
    • offset (str) – The period to shift by as specified by Java’s Period.parse().
    • dense (bool) – If False, the returned measure will evaluate to None everywhere the input measure evaluates to None. If True, the returned measure will be evaluated on all the queried members of the on hierarchy, even if the input measure evaluates to None there. In any case, facts are never “created”: if measure evaluates to a non-None value on 2025-01-01 and offset="-P2D" but 2025-01-03 is not a member of the on hierarchy, 2025-01-03 will remain absent from the query results.
    • fallback (Literal [ ‘past’ , ‘interpolated’ , ‘future’ ] | None) – The value to use if measure evaluates to None at the shifted location:
      • None: No value.
      • past: Value at the previous date in chronological order.
      • interpolated: Linear interpolation of the values at the past and future existing dates or None if either date is missing.
      • future: Value at the next date in chronological order.
  • Return type: MeasureDefinition

Example

Explanations:
  • Exact (+):
    • The value for 2020-08-31 is taken from 2020-09-30 even though 31 != 30 because there are both the last day of their respective month.
  • Exact (-):
    • The value for 2020-10-31 is taken from 2020-09-30 for the same reason.
  • Interpolated:
    • 10.00, 21.00, 21.00, and 9.00: no interpolation required since there is an exact match.
    • 15.31: linear interpolation of 2020-09-01’s 10 and 2020-09-30’s 21 at 2020-09-15.
    • 8.03: linear interpolation of 2020-10-01’s 9 and 2020-10-31’s 8 at 2020-10-30.
    • ∅: no interpolation possible because there are no records after 2020-10-31.
Behavior of the dense parameter:
Explanations:
  • Sparse:
    • There is no value for (2020-09-01, London) because, although both members exist separately, no fact contains both simultaneously.
  • Dense:
    • The value for (2020-09-01, London) is taken from (2020-10-01, London).
    • There are no values for 2020-10-01 because 2020-11-01 is not a member of the Date hierarchy.
See also: shift().