Years between

I have a text column with this value:
2018 - 2021
I would like to find an expression that can calculate the years between this range.
The output should be an EnumList:
2018, 2019, 2020, 2021

List Generator Expressions Feature Requests

NUMBERLIST(0,10) = {0,1,2,3,4,5,6,7,8,9,10} DATELIST(TODAY() , TODAY()+7) = {2/3/21 , 2/4/21,… , 2/10/21} ALPHALIST(β€œa” , β€œd”) = {β€œa” , β€œb” , β€œc” , β€œd”} DECIMALLIST(0,0.5,0.1) = {0,0.1,0.2,0.3,0.4,0.5}

1 Like

Set up a Table that is just a list of years.

Then pull a matching List from that:

FILTER(
  year ,
  AND(
    [year] <= NUMBER( INDEX( SPLIT( [text] , " - " ) , 2 )
    [year] >= NUMBER( INDEX( SPLIT( [text] , " - " ) , 1 )
  )
)

4 Likes

Thank you very much @Marc_Dillon. Instead of using an extra table, could I also hardcode the years list in the expression?

I can’t think of any way. Because you need to filter an existing list of dates, by comparing against your start and end. There is no way to do something like this:

FILTER(
  LIST(x,y,z)
  ...
)

3 Likes

Like this?

TOP(
  LIST(
    (YEAR([Date]) - 0),
    (YEAR([Date]) - 1),
    (YEAR([Date]) - 2),
    ...,
    (YEAR([Date]) - N),
  ),
  M
)

Where N is the most number of years you’ll allow, M is the number you need now, and M <= N.

4 Likes

Thank you @Marc_Dillon and @Steve these both very good solutions.

2 Likes