I am looking for a formula that will return data from the previous month. I know I could use a simple filter tool and define my dates each month, but I would like to automate the process so it's always looking back at the previous months data.
Example: Today is 6/6/2018, I would like all data from 5/1/2018-5/31/2018
In 2 months (8/6/2018), I would like data from 7/1/2018-7/31/2018
Solved! Go to Solution.
@IJH34 Make sure your incoming field is already a date field and try this expression in your Filter tool then keep the T output:
ToNumber(DateTimeMonth(DateTimeToday()))-tonumber(DateTimeMonth([date]))=1
@Kenda Close! This also includes data from the current month. I only wants last months data.
@IJH34 I had realized that just after I posted and actually edited the formula. Try the one in my previous post now.
That formula doesn't account for the year of the data so it will take take from the previous month of last year too. It won't work during January either when the current month is 1 - previous month 12.
Here is another formula I tried that should work for those situations.
[date] <= ToDate(DateTimeAdd(DateTimeFirstOfMonth(), -1, "days")) and [date] >= ToDate(DateTimeAdd(DateTimeFirstOfMonth(), -1, "months"))
This does the trick! Thank you so much!
@zwiskur The ToDate function comes from https://jdunkerley.co.uk/2016/05/15/alteryx-formula-add-ins-v1-1/
User | Count |
---|---|
16 | |
14 | |
10 | |
6 | |
6 |