Question
How can I dynamically display the last 5 years in Appian?
A
Anonymous
December 10, 2025

Answer

Code :

a!localVariables(
/* Get the current year as an integer */
local!currentYear: year(now()),

/* Generate a list of the last 5 years */
local!lastFiveYears: a!forEach(
/* Enumerate creates a list of numbers {0, 1, 2, 3, 4} for the 5 years */
items: enumerate(5),

/* The expression for each item: current year minus the item index (0 through 4)
This creates the list: {2025, 2024, 2023, 2022, 2021} (assuming current year is 2025) */
expression: local!currentYear - fv!item
),
local!lastFiveYears
)


Explanation of Key Functions

  1. now(): Returns the current date and time.
  2. year(): Extracts the year (as an integer) from a given date.
  3. a!localVariables(): Defines local variables to make the expression clean and readable.
  4. enumerate(5): Creates a list of integers starting from 0 up to N-1, so enumerate(5) produces {0, 1, 2, 3, 4}.
  5. a!forEach(): Iterates over a list (items) and applies an expression to each item (fv!item).


Output:

Image 38


JuniorSeniorExpressions#sailcoding
Loading comments...