20/23

Generate Last N Years

Easy

Given an input n, generate a list containing the last n years in chronological order, including the current year.

For example, if the current year is 2026:

  1. n = 5 → {2022, 2023, 2024, 2025, 2026}
  2. n = 3 → {2024, 2025, 2026}


Requirements

  1. Use Appian expression functions.
  2. The value of n should determine how many years are returned.
  3. Include the current year.
  4. Return the years from oldest to newest.
  5. Do not use reverse().


Restrictions

Solve this without using reverse().

ri! Rule Inputs

ri!nNumber (Integer)
5

Example 1 — Case 1

Input: ri!n
5
Output:
{
  2022,
  2023,
  2024,
  2025,
  2026
}

Example 2 — Case 2

Input: ri!n
3
Output:
{
  2024,
  2025,
  2026
}

Example 3 — Case 3

Input: ri!n
8
Output:
{
  2019,
  2020,
  2021,
  2022,
  2023,
  2024,
  2025,
  2026
}

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter