Let’s talk Alteryx Copilot. Join the live AMA event to connect with the Alteryx team, ask questions, and hear how others are exploring what Copilot can do. Have Copilot questions? Ask here!
Start Free Trial

Alteryx Designer Desktop Discussions

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

Return the first date or last date or the previous month

jennpm11
5 - Atom

Hi there,

 

I'm fairly new to Alteryx and I'm struggling to come up with the right formula.

 

What I need is if a date is less than the first of the previous month then return the first of the previous month. Also if a date is greater than last day of the previous month return the last of the month previous month.

 

This is what I have but it's not going to work for months that don't have 31 days. 

 

datetimeadd(datetimefirstofmonth(),-1,'days')

 

datetimeadd(datetimefirstofmonth(),-31,'days')

 

if [Date]>[Find last day of the month]then[Find last day of the month]
else (if [DATE]<[Find first day of the month]then[Find first day of the month]
else [DATE] endif) endif

 

Any help is appreciated!

Thanks,

Jenn

 

2 REPLIES 2
Laurap1228
11 - Bolide

Try this:

date formula.PNG

jennpm11
5 - Atom

Yes! This works perfectly

 

Thanks so much

-Jenn

Labels
Top Solution Authors