Alteryx Designer Desktop Discussions

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

Formula needed for reading last two digits in a numeric value

Jake5
8 - Asteroid

Hello, I'm trying to write out an if/else formula that converts a current month value to previous month whereby the field values are expressed numerically (202112, 202201, 202202, etc).  For 11 months out of the year, the formula [Current Month] -1 suffices.  However, this becomes problematic when Current Month ends in 01 because [202201] -1 = 202200.  For January, the formula would instead need to read as [202201] -89 = 202112.

 

How would I write out a formula to where "IF Current Month ends in '01', then [Current Month] - 89 else [Current Month] -1 endif?

5 REPLIES 5
DataNath
17 - Castor

Hey @Jake5, how does this look? As the field will most likely be read numerically, you just need to use the ToString() function so that you can also apply the EndsWith() function - which only works on strings - to check for the '01'.

 

DataNath_0-1659537957468.png

binuacs
20 - Arcturus

@Jake5 One way of doing this by converting the given date to Date type and find the previous month

 

binuacs_0-1659538383312.png

 

Jake5
8 - Asteroid

Thank you both!  Both solutions worked.

Watermark
12 - Quasar
12 - Quasar

Jake, 

 

Is there any reason you're married to the '220201' format?  If they're dates, you may want to convert and use them as dates. 

 

2022-08-03_10-01-59.jpg

Jake5
8 - Asteroid

I may consider using the date option.  Either works.  

Labels