on 07-10-2018 01:56 PM - edited on 08-03-2021 11:24 AM by csalgado5
This article is part of the Tool Mastery Series, a compilation of Knowledge Base contributions to introduce diverse working examples for Designer Tools. Here we’ll delve into uses of the Date Tool on our way to mastering the Alteryx Designer:
You’re creating an app that involves dates. You want the user to be able to dynamically select the dates being used in the app, though. The tools you already know may not work. A Text Box would be too messy and allow lots of room for error. Pre-defined Drop Downs and List Boxes aren’t dynamic enough. Ah ha! What about that tool that looks like a calendar? The Date tool in the Interface category provides the perfect solution!
Note:This Tool Mastery assumes you have basic knowledge of apps and how to create them. If you need to brush up on this knowledge, review this Tool Mastery. You could also complete tutorial 6 in your designer or read this documentation page online.
The Date tool has minimal configuration. In fact, the tool/app could run successfully even if the configuration is never changed whatsoever from the time the tool is put on the canvas. In order for the app to make more sense to the user, though, I recommend changing the configuration settings. Simply type in the textbox the phrase that you wish to be displayed above the calendar to the user when they run the app.
Typically, this will be something like
The user will then be able to select whichever date they like, and that will flow through the workflow. Then, you can Filter, use this date in a Formula tool, or anything else you would normally want to do with a date.
See the attached 2018.1 files,Date Tool Mastery 1.yxwz, Date Tool Mastery 2.yxzp, and Date Tool Mastery 3.yxzp, to follow along below and to see the Date tool in action.
1. Calculate how many days there are between today and the date selected
In the first example, a Generate Rows tool is used simply to create a record with today’s date. The Formula tool first creates a field with the value of the user’s date, getting the date input using a constant. Secondly, the Formula tool creates a field that calculates the difference, in days, between the user selected date and today.
Note: In the attached workflows, you will see that Action tools are not used. Instead, the output from the Date tools are being captured using a workflow constant in the “%Question.ToolName%” format. An Action tool could be used, but I like using this way because it looks cleaner and is easier for me. To learn more about using constants, see this article on the Community.
The user will see a calendar appear when they run the app. Today’s date will have a blue border. Once the use selects a date, it will be highlighted blue. Once they click ‘Finish’ the date will flow through to the downstream processes.
Depending on how the app is set up, results may appear to the user. In this case, the Browse appears when clicking Finish. Other apps may write to a file or kick off the start of another app.
2. Sum the sales between two dates
Apps don’t have to be limited to just one Date tool. In the next example, two Date tools are used to capture sales, by category, for a company between two user selected dates.
In this app, the user is interested in the sales for each product category. One user may be interested in just the second quarter, however, while another user may want to see sales for the entire year of 2017. The Date tool allows for all of these possibilities.
As @NicoleJohnson and @MarqueeCrew explained in this discussion board, there is no way to set min and max values to limit the user’s choices on the front end. You can add an Error Message tool, though, so that the app displays an error if the selected date is not within a range set inside the app’s workflow.
In this specific example, an Error Message tool is used to verify that the end date is after the start date. Also here, if the user selects a date range that is not contained in the data, no records will appear in the output.
3. Find out what has happened on a specific date in history
Need to include the input date as part of a dynamic string? The next example enables you to see what has happened on a certain date and any well-known births and deaths on that date by modifying a URL with the user's chosen date.
In this example, the Formula tool first uses the date from the Date tool and appends it to the URL, formatting as necessary. Concatenating is easy. Per usual, just include the strings that you want to bring together separated by a ‘+’ symbol.
[Address]+LowerCase(DateTimeFormat("%Question.Date%","%B/%d"))
This Formula tool also creates a field that includes the chosen date and will be used as the header/title of the report.
"On this day: " + DateTimeFormat("%Question.Date%","%B %d")
From here, the macro takes the generated URL and grabs all of the necessary information from https://www.timeanddate.com/on-this-day/ then formats it so it can be easily read. A table is created to view the output.
This can be extended to any URL you know that has a date in it (modifying the macro to match each URL’s incoming format, of course)! Here are just a couple illustrations:
In this discussion on the Community, a user was struggling using the Date tool for the first time and @patrick_digan was able to point them in the right direction by checking their use of quotes.
If you need to brush up on how to manipulate the date format that is coming from the Date tool, check out this documentation guide.
By now, you should have expert-level proficiency with theDate Tool! If you can think of a use case we left out, feel free to use the comments section below! Consider yourself a Tool Master already? Let us know atcommunity@alteryx.comif you’d like your creative tool uses to be featured in the Tool Mastery Series.
Stay tuned with our latest posts everyTool Tuesdayby followingAlteryxon Twitter! If you want to master all the Designer tools, considersubscribingfor email notifications.
Hi there. I'm an Alteryx newbie. I'm trying to mimic the first workflow. However I kept getting "%Question.Date%" in the Selected Date column. Not sure why. can you please help?
Thank you so much!!!
Thank you for this @Kenda - I've been using the workflow constants for ages to test macros, but didn't know that there was a way to bring them into the workflow using the "%Question.Date%" in a formula tool.
Good learning on a Sunday morning!
Hi Kenda,
Thanks for sharing this. I am trying to rebuild the samples and cannot move forward with the 1st one. I should have built the same app. But when I run it as an app, it cannot get the date selected from the calendar and generating no output. What could be the possible reasons?
Regards,
Cliff
Hi @JokeFun
There could be a couple reasons for this. If you download the example, are you able to run it successfully? If so, I would recommend comparing what you built to the version attached to see where any differences are.
A couple places I would recommend looking first would be
-in your Interface designer, do you have the check box checked to show the user the Browse on success?
-in your configuration of the date tool, do you have the Name labelled as the same thing you're calling it within the workflow?
-have you tried running it in designer (not in the app interface), and does that give you results you're expecting?