Question

Filtering based on relative date

  • 14 September 2021
  • 2 replies
  • 1 view

I'm trying to filter records for the last three years of data but want to avoid having to edit the transformer on a yearly basis (ie. TestFilter: Year= 2021, Year= 2020, Year = 2019 - necessitating a yearly update at the change of the year). I'm hoping to find a way to set up an attribute filter or test filter that can be set on the relative time frame (ie. Year = this year, Year = last year, Year = two years ago). I'm guessing there is a simple way to do this with the text editor but I haven't been able to figure it out!


2 replies

Badge +2

Hi @kcarlsonham​ ,

 

Good question, you can get this done with a TestFilter using the DateTimeFunctions in the Text Editor. Try using the following: 

@DateTimeFormat(@DateTimeAdd(@DateTimeNow(),-P1Y),%Y)

-P1Y for the previous year and -P2Y for 2 years ago. 

2021-09-14_13-56-15 

Badge +2

Hi @kcarlsonham​ ,

 

Good question, you can get this done with a TestFilter using the DateTimeFunctions in the Text Editor. Try using the following: 

@DateTimeFormat(@DateTimeAdd(@DateTimeNow(),-P1Y),%Y)

-P1Y for the previous year and -P2Y for 2 years ago. 

2021-09-14_13-56-15 

I should note... this is also possible by creating a new date attribute (DateTimeStamper > DateTimeCalculator (subtract 1 and 2 years) > DateTimeConverter) if you want to set it up using transformers instead. Depends on your preference 😉 

Reply