Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Filter last 12 months irrespective of day?

Crispy131
8 - Asteroid

Hello, 

 

I am trying to filter my dataset so that it only returns the last 12 months but includes all the data from the 1st of the month 12 months ago.

 

Right now I'm using the following formula:

 

[OpenDate] >= DateTimeAdd(DateTimeToday(),-12,"months")

 

So for instance if today is 24th November 2022 the earliest data it shows me is from 24th November 2021. However I would like to adjust this so that it looks at the month we're in today and returns the last 12 months from day one of that month. So for this example the data returned would start from 1st November 2021.

 

Not sure if this is achievable... any help is much appreciated! 

3 REPLIES 3
Felipe_Ribeir0
16 - Nebula

Hi @Crispy131 

 

Two ways to adapt your formula to do this:

[OpenDate] >= DateTimeFormat(DateTimeAdd(DateTimeToday(),-12,"months"), '%Y-%m-01')

[OpenDate] >= DateTimeTrim(DateTimeAdd(DateTimeToday(),-12,"months"), 'firstofmonth')

Felipe_Ribeir0_0-1669293573367.png

 

 

DataNath
17 - Castor

Hey @Crispy131, you can use the DateTimeFirstOfMonth() function to return the first day of the current month and then implement the same kind of filter expression. The following works - example here where I generated all dates since 1st Jan 2020:

 

[Date] >= ToDate(DateTimeAdd(DateTimeFirstOfMonth(),-12,"months"))

 

DataNath_0-1669293092233.png

 

Crispy131
8 - Asteroid

Brilliant! Thank you

Labels