Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Month number calculation for to include past months

bcooke
5 - Atom

Hello all,

 

Currently working on trying to get a formula to calculate the current month but -2. i.e. want it to populate if 10 to output 8. Although when January or February comes around current month of 1 or 2 will be incorrect as it will output -1 and 0. Is there a way I can have if it say January to output 11 for November and February output 12?

 

Current Formula being used below: 

DateTimeMonth(DateTimeToday())-2)

Again the above formula would not calculate correctly for January and February.

5 REPLIES 5
BrandonB
Alteryx
Alteryx

DateTimeFormat(DateTimeAdd(DateTimeFirstOfMonth(),-2,"Months"),"%m")

 

This will do the trick for you. The first formula shows you that you can do a datetimeadd which will subtract two months from the first of the current month. The second formula shows you the exact same formula as the one above, except it is using datetimeformat to pull out the month number. You only need the second formula for your purpose but I wanted to show both so it makes sense what is happening. 

 

Dates.png

bcooke
5 - Atom

Hello BrandonB!

 

Appreciate the help. It worked perfectly and even added the 0 that I would of needed also.

 

Thanks again,

 

-bcooke

BrandonB
Alteryx
Alteryx

Of course! If you ever run into a situation where you need leading zeroes, another handy function is PadLeft(String, len, char)

 

If you have single digits for some and double digits for others and need everything to be two characters with a zero added to the front if not, it would look like this:

 

PadLeft([String with the digits], 2, "0")

 

This will add a zero to the front of the values until they are two characters long. You can adapt this to other situations by changing 2 to whatever length you need and the "0" to whatever character you need.

Ye_Olde_Baller
6 - Meteoroid

I am trying to do the following:

if paid date month is less than or equal to incurred date month +3 months = y else no,

 

Dates are in YYYY-MM-DD format.

BrandonB
Alteryx
Alteryx

@Ye_Olde_Baller it should be something like this, assuming that your paid date month and incurred date month are both date data types. If not, you will want to use a date time parse tool prior to this formula to get them into a date data type. 

IF [Paid Date Month] <= DateTimeAdd([Incurred Date Month], 3, "months")

THEN "y"

ELSE "no"

ENDIF

Labels