Tableau comparison calculation between integer dates - tableau-api

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

Related

Have Max value of range of dates filter be todays date

I have a "Range of Dates" filter and what I want is for the max (or right most value) to always be the most recent date which should be today's date. What seems to be happening is that if I leave the dashboard open and come back the next day the max value is yesterday's date and I must manually move the slider over to be today's date. How can I accomplish this?
I find a calculated field is the best way to do this as I have run into the same issues using the out of the box max date filter.
Create a calculated field as follows:
[date] = {FIXED: max([date])}
This creates a True False field where only the records that have the max data and carried through.
Now drag this onto the filter pane and select 'TRUE'.
I've generally seen two basic approaches for this problem: Calculated fields and relative dates.
Use a calculated field or parameter or some combination of calculated fields and parameters with filters. This is similar to what smb suggests in their answer to this question. It also seems to be the most popular approach.
If you don't particularly care about being able to set the end-date with the slider, you could try using relative dates, using the approaches detailed in the accepted answer to this Tableau forum question and in this Tableau Knowledge Base article. Jennifer Vonhagel also gives a second answer to the Tableau forum question farther down that uses a parameter plus calculated field approach.
Additionally, this Tableau Knowledge Base article offers another option (Option 1, in the article) if you have Tableau 10.3+: You can use the "Latest Date Preset" (see here for details) check box in the date filter dialog box. I haven't used this, but it looks promising if you're using Tableau Desktop (seems like it wouldn't work for Tableau Web). The article's Options 2-4 are just riffs on calculated fields, in my opinion.
Two more approaches I've heard of – but never personally seen in the wild:
Push the max date down into the view you put Tableau on top of and let the view do the work.
Use a script to modify the Tableau workbook's XML.

Set the latest date value to the Quick Filter in TABLEAU

There is a live worksheet called Person with columns - Names & Birthdays. Need to create a quick filter with a default value pointing to the latest birthday.
For example: If there are 3 Records as follows,
Names Birthdays
A 8/9/1993
S 6/5/1994
Z 8/15/2000
The filter should hold the default value 8/15/2000 in it with other values unchecked in the drop down list.
I believe I see what you are asking. When you add your filter click the little drop down arrow in the filter --> edit filter-->select the tab labeled "Top"--> by field radio button==>Top from the first drop down-->enter 1 in the next field which will say by after it-->select birthday from the next drop down--then maximum. This will change the view to show only the most recent birthdate. Hope this helps.
Tableau currently doesn't give you dynamic control over quick filter defaults. For dates. They generally start out with the settings that were published.
Here are a few easy suggestions that are similar to, but not exactly, what you want. At the end, there is a way to do exactly what you want at the cost of more effort.
For continuous date fields, you can set the filter to show Relative Dates and the filter allows the user to easily set a range of dates showing the last N days, weeks or months relative to an anchor date. The anchor date defaults to the current date.
For discrete date fields, you can display a top filter as tia97 recommended, and show an integer valued parameter control to allow the user to pick N to see the latest N birthdays. (i.e. the N youngest people)
You could try other variations using parameters, calculated fields and quick filters, but it might be simpler to just show the list of birthdates and let people choose.
Finally, if you are publishing this workbook to Tableau Server, you can use the Javascript API to control the filtering user experience yourself. You can embed the Tableau visualization in a web page, surrounded by custom HTML, CSS and Javascript that you define. Build whatever controls you want for user interaction, and then send JavaScript commands to Tableau to direct the filter actions. More effort, but you get a lot more control over the UX.
Generally, I'd use the builtin features in Tableau Desktop as far as they go to get most of your desired UX quickly and easily, and then save the JavaScript API work for final polish on only your most public visualizations that really need it.

How to return a cell value if the date in a range of cells is today in google sheets

I currently have a Google Sheet, with numerous sheets in it, to track contract deadlines for different clients. One of these sheets shows me all of the deadlines in Columns E:M for every contract. Each row is a separate contract.
I'm trying to create a separate sheet that will show me the client's name, found in column A, if a date in columns E:M is Today. That way I can look at one page and see all the clients that have a deadline today. Here is what I tried with no success:
=if('U/C(Dont Edit)'E2:M2=TODAY(),'U/C(Dont Edit)'A2,"")
"U/C(Dont Edit)" is the sheet that shows all of the contracts.
I believe the problem lies when I try to apply "=Today()" to a range(E:M). It seems to work fine if I just use E2=Today(). It looks like I could accomplish my goal using If statements within If statements, but that gets very messy very quickly and I'm hoping there is a better way.
Thanks in advance for your help.
You can do it with the COUNTIF() function per row:
=IF(COUNTIF(E2:M2,TODAY())>0,A2,"")
But I think a better solution is to use the FILTER() function. It will give you a list of names:
=FILTER(A2:A,(E2:E=TODAY())+(F2:F=TODAY())+(G2:G=TODAY())+(H2:H=TODAY())+
(I2:I=TODAY())+(J2:J=TODAY())+(K2:K=TODAY())+(L2:L=TODAY())+(M2:M=TODAY()))
I suggest #dePatinkin's solution (for and additional column, say N, containing the COUNTIF formula from Row2 downwards) in combination with a query (in another sheet):
=query('U/C(Dont Edit)'!A:N,"select * where N is not NULL")
This assumes your existing sheet has the columns labelled.
You might combine the above with Conditional formatting to indicate which column has the date in it (today) that triggered the row selection.

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.

Default range for date range filter in tableau

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.