Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Filtering Data Based on Previous Month

LorenzTaylor
8 - Asteroid

Hello -

This may be a simple question.


I have an historical dataset that goes back multiple Years. I Would like to filter this data set to only show the previous Months Data in the workflow. The main reason I do not want to set a constant date is because every time the workflow runs, it needs to pull the previous months data. For example it is 05-09-2024, this workflow will need to pull all data from (04-01-2021) - (04-30-2024). If the date is currently (06-01-2024), this workflow will need to pull (05-01-2024) - (05-31-2024).

Please see attached for desired output.

3 REPLIES 3
Luke_C
17 - Castor
17 - Castor

Hi @LorenzTaylor 

 

Try this in a custom filter: 

[Date] >= todate(datetimetrim(datetimeadd(datetimenow(),-1,'month'),'firstofmonth'))

and 

[Date] <= todate(datetimetrim(datetimeadd(datetimenow(),-1,'month'),'lastofmonth'))
cmcclellan
13 - Pulsar

Hi @LorenzTaylor 

 

Put this is in a filter:

DateTimeAdd(DateTimeTrim(DateTimeToday(), 'month'),-1,'month') = DateTimeTrim([Date], 'month')

 

It's basically saying what you asked - take today's date (ie 5/10), trim it to month (ie 5/1) subtract a month (ie 4/1) and compare to your data that's been trimmed to month as well 

Swathi
9 - Comet

May be you want to convert the dates to Alteryx default format of YYYY-MM-DD before you use the above solutions.

Labels