Hi team,
I have been trying to get year and month difference between two dates. It is possible in excel through datedif() function. However, I am unable to get the same on alteryx. Below is the example:
Any help would be highly appreciated!
Hey @sahelmajid,
Alteryx is optimised to only allow date calculations with date data types. There is a good quick video on data types on the community here: Understanding Data Types - Alteryx Community. To convert your text to date data types I use the date time tool then a formula to calculate the difference and format the values:
The community has some quick and easy videos on formulas and the Formula Tool here https://community.alteryx.com/t5/Interactive-Lessons/tkb-p/interactive-lessons/label-name/Writing%20Expressions
Any questions or issues please askIra WattTechnical ConsultantWatt@Bulien.com
@sahelmajid Another way of doing this with the DateTime functions
Thank you so much! That helps. Just curious, what if we want to add days to it as well?
Can we do that as well with alteryx workflow?
@sahelmajid that is an interesting one, I haven't been able to figure out how to add leap days into the calculation which I assume is what is throwing off the number of days:
Always find these fun and was definitely a little trickier than I first anticipated so decided to have a little stab! If there's any issues when you try applying this to a larger dataset then let me know and I can revisit the logic.
Obviously you can trim out the actual Years/Month/Days fields with a Select tool afterwards if you don't want them hanging around, or can even compress all of the expressions into one if you don't mind playing around and ending up with a single, mammoth statement.
@IraWatt@DataNath Thank you so much for your help! Both of these workflows run perfect even on large datasets.
Great to hear @sahelmajid ! Make sure to leave a green tick on replies which solve your problem. Have a great week 😄