In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Formula Help: How to get sum of previous month value?

akim55
5 - Atom

helpIf the  table looks like this:

03/01/20228
03/03/20223
03/04/20223
03/15/20225
03/21/20227
04/01/20226
04/15/20221
04/18/20229

What would be the formula to get the sum of the previous month from the current month date? 

Right now, I have the previous month's sum formula as:

 

 

 

IF ToNumber(DateTimeMonth(DateTimeToday()))-tonumber(DateTimeMonth([spent_date])) = 1 AND DateTimeYear([spent_date]) = DateTimeYear(DateTimeToday())THEN [Sum_hours] ELSE 0 ENDIF

 

 

 

 

If the formula is correct, can someone explain why it is correct and/or if there is a better way to get the data? Thank you in advance. 

2 REPLIES 2
gabrielvilella
14 - Magnetar

The expression is correct. I encourage you to take a look at the documentation and see what each of those formulas means.

https://help.alteryx.com/20214/designer/datetime-functions 

 

Also, here is another way of doing this, which I personally think it is simpler and easier to understand:

IF DateTimeTrim([spent_date],'month') = DateTimeAdd(DateTimeTrim(DateTimeNow(),'month'),-1,'month')
THEN [Sum_hours]
ELSE 0
ENDIF

 

PhilipMannering
16 - Nebula
16 - Nebula

@gabrielvilella And you can also replace 

DateTimeTrim(DateTimeNow(),'month')

with

DateTimeFirstOfMonth()
Labels
Top Solution Authors