Getting Year and Month difference in alteryx
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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%20...
Any questions or issues please ask
Ira Watt
Technical Consultant
Watt@Bulien.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@IraWatt @DataNath Thank you so much for your help! Both of these workflows run perfect even on large datasets.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Great to hear @sahelmajid ! Make sure to leave a green tick on replies which solve your problem. Have a great week 😄
