Default range for date range filter in tableau - tableau-api

I want to set the default range on a date filter to show me the last 10 days - so basically looking at the lastDate (max date) in the data and default filtering only on the last 10 days (maxDate - 10)
How it looks now:
I still would want to the see the entire range bar on the dashboard and give the user the ability to modify the selected range if he wants to. The maxDate changes after every data refresh so it has to be some sort of a condition that is applied to the filter.
How I want it to look (by default after every refresh of data - new dates coming in):
Any suggestions on how this can be done? I know I can use the relative date and show the data for last 10 days but that would modify the filter and create a drop down which I don't want.
Any suggestions are welcome!

One simple approach that does most of what you want is the following:
Create an integer valued parameter with a range from 1 to some max
you choose, say 100. Call it say num_days.
Show the parameter control on your dashboard as a slider, and give
it a nice title like "Number of days to display"
Create a boolean calculated field called Within_Day_Range defined as:
datediff('minute', [My_Date_Field], now()) < [num_days] * 24 * 60
Put Within_Day_Range on the filter shelf and select the value true.
This lets the user easily select how many days in the past to include, and works to the granularity of minutes (i.e. the last two days really means the last 48 hours, not starting at midnight yesterday). Adjust the calculated field if you want different behavior.
The main drawback of this approach as described so far is that it doesn't display the earliest date possible in the database because that is filtered out. Quick filters do an initial query to get the bounds, which has a performance cost -- so using the approach described here can avoid that query and thus load faster.
If you really need that information on your dashboard, you could create a different worksheet to get just the min([My_Date_Field]) and display that near your parameter control.

Related

How to combine 5 columns into 1 filter in Tableau?

My (simplified) data structure is as follows:
I have flagged whether my users have performed a certain action in the last 7 days, 14 days, 1 month, 6 months, and 1 year (1 means the user has performed the action and 0 means he has not). I would like to create a drop-down filter in Tableau where I would be able to filter out the users who have performed the action in the last 7 days, 14 days, 1 month, 6 months, and 1 year. I will have a total number of users at the top of my dashboard and an "action date" filter. Does anyone know how I can achieve this kind of filter in Tableau? I believe I have to create a parameter but I am not sure how to combine these 5 columns into 1 filter.
Any help is appreciated!
The easiest approach to explain is to create a parameter that allows the user to select exactly one value from a prescribed list of strings, such as "7 days", "14 days"... etc. You may also want a few other choices like "Start of Time", or "All users". Whatever options you like.
Then create a (boolean) calculated field that denotes whether the current data record should be included based on the current parameter value. Something like
if [My Filter Param] = "7 Days" then
[7 Days] = 1
elseif [My Filter Param] = "14 Days" then
[14 Days] = 1
...
else // last one
[My Filter Param] = "Start of Time"
end
Then put your calculated field on the filter shelf, choose True as the filter value, apply to whatever worksheets or data sources matter, and of course display your parameter control.
This is a pretty general technique, combine a parameter (for asking the user to make a choice) with a boolean calculated field (to apply the users choice) and the filter or other shelf for applying that calculation to a visualization. Works for all kinds of problems.
If your data sets are large or slow, you can optimize performance in a few ways. Say by using boolean fields in your data instead of integers, and by using integer valued parameters instead of strings so you can use a fast case statement to replace all the string comparisons (although Tableau can optimize some of those comparisons away) If you do use an integer parameter, you can still define the choices to display meaningful strings in the parameter control. See the edit parameter dialog.
Finally, you could consider making your analysis and viz a little more flexible by adjusting your pre-processing to produce data with just two columns -- User and Date_of_Last_Key_Action . Then your users could just use the built-in date filter controls in Tableau to view based on any time range, .e.g, the last 13.5 days if they wanted. You wouldn't need a parameter or calculated field in that case.
You can also re-shape your data. Do like the screenshot GIF

Tableau Target Vs. Actual - Can not get totals to show correctly

I am having trouble showing the correct totals in my tableau worksheet.
I have supervisors that are part of specific zones that need to complete a certain number of tests in different categories. For example, supervisor 15716 must complete 8 tests in category 1. I need to show the target, which is a number stored in the database and show the actual number of tests in that category that have been completed within a date range. I have it working, but Im not sure if I did it correctly because I can not show any totals.
System target - number stored in database
CountOfSheetID - calculated field
Percent Compliant - calculated field
Try this approach -
First define a calculated field called [Within Date Range?] as
[Date] >= [MyStartDate] AND [Date] <= [LastSelectedDayOfMonth]
and put that new field on the filter shelf, only including data where [Within Date Range?] is True. (You could also just filter the [Date] field if that is flexible enough for you)
The you don't need the CountofSheetId calculated field at all. If you want to know how many records have a non-null value for [SheetID] within your date range, you can simply drop [SheetID] on a shelf and choose to treat it as Measure with the aggregation function COUNT()
Then just build your visualization to show the counts you want (not percentages, the actual counts)
Finally, you can convert counts into Percentages by clicking on the pills for your Measures and choosing Percentage under Quick Table Calcs. You'll want to experiment with the "Compute Using" setting to tell Tableau how to compute your percentages -- i.e. define percentage of "what".
Percentages are implemented as table calcs in Tableau. Read the help to understand table calcs, especially the description of partitioning and addressing.

Tableau comparison calculation between integer dates

I'm currently struggling with a calculation I'm trying to create in Tableau so any help you can provide would be great.
Basically I have a calculated field within Tableau called [ExampleCount] which is a count distinct based on a simple Yes/No condition.
I have this information displayed on two separate sheets in a dashboard, one filtered for the current activity month and one for the previous.
What I now need to do is have another sheet with the same calculation of [ExampleCount] but showing the difference between the current/previous months.
So: [ExampleCount (This Activity Month)] - [ExampleCount (Previous Activity Month)]
The Activity month is an integer value, currently ranging from 1 - 9.
I feel like this should be a simple calculation but I've tried several different methods and have been unable to come up with anything conclusive.
It would also be good if this could change periodically.
Kind Regards,
Plain_Lazy

Tableau - Filter/Parameter For Different Date Ranges

I am trying to set up a filter or parameter for different date ranges in Tableau, such as:
Previous Week
Previous 4-Weeks
Previous 8-Weeks
based on the most recent data in the database. Is this possible?
Edit:
I should have been more clear here.
Is it possible to only have these options in the filter and have it based on the maximum date in the database?
Update
Based on your comment and updated question, you can do it as you intend, though it isn't as straight-forward.
NOTE: I did this very quickly and with a random data set, so it will be important for you to test this thoroughly with your data set.
Steps:
Create a parameter control that the users will use to change the selected date range. I created this as a list of strings with values that I can use directly in a calculated (after simple casting):
Create a calculated field that you will use as a filter that references the selection of the parameter control. It tests to see if the difference (in weeks) between the maximum date in the view and the date of any given row is less than the value of the parameter.
Calculation: INT([Date Filter Parameter]) > DATEDIFF("week",ATTR([Date Field]),WINDOW_MAX(MAX([Date Field])))
Place the calculated field in the filter box and set it to True.
You will be able to filter your data like so:
Original Answer
Yup - that is built into Tableau.
Add your date to the filter and select the "Relative Date" option:
You can set the defaults - users can change these later:
Then just "Show Filter":

Tableau Future and Current References

Tough problem I am working on here.
I have a table of CustomerIDs and CallDates. I want to measure whether there is a 'repeat call' within a certain period of time (up to 30 days).
I plan on creating a parameter called RepeatTime which is a range from 0 - 30 days, so the user can slide a scale to see the number/percentage of total repeats.
In Excel, I have this working. I sort CustomerID in order and then sort CallDate from earliest to latest. I then have formulas like:
=IF(AND(CurrentCustomerID = FutureCustomerID, FutureCallDate - CurrentCallDate <= RepeatTime), 1,0)
CurrentCustomerID = the current row, and the FutureCustomerID = the following row (so it is saying if the customer ID is the same).
FutureCallDate = the following row and the CurrentCallDate = the current row. It is subtracting the future call time from the first call time to measure the time in between.
The goal is to be able to see, dynamically, how many customers called in for a specific reason within maybe 4 hours or 1 day or 5 days, etc. All of the way up until 30 days (this is our actual metric but it is good to see the calls which are repeats within a shorter time frame so we can investigate).
I had a similar problem, see here for detailed version Array calculation in Tableau, maxif routine
In your case, that is basically the same thing as mine, so you could apply that solution, but I find it easier to understand the one I'm about to give, I would do:
1) Create a calculated field called RepeatTime:
DATEDIFF('day',MAX(CallDates),LOOKUP(MAX(CallDates),-1))
This will calculated how many days have passed since the last call to the current. You can add a IFNULL not to get Null values for the first entry.
2) Drag CustomersID, CallDates and RepeatTime to the worksheet (can be on the marks tab, don't need to be on rows or column).
3) Configure the table calculation of RepeatTIme, Compute using Advanced..., partitioning CustomersID, Adressing CallDates
Also Sort by Field CallDates, Maximum, Ascending.
This will guarantee the table calculation works properly
4) Now you have a base that you can use for what you need. You can either export it to csv or mdb and connect to it.
The best approach, actually, is to have this RepeatTime field calculated outside Tableau, on your database, so it's already there when you connect to it. But this is a way to use Tableau to do the calculation for you.
Unfortunately there's no direct way to do this directly with your database.