Tableau Filter on field which contains MAX of another field - tableau-api

I have a table in Tableau that contains football teams, their top goal scorers and the number of goals these players scored. I would like to filter the table to show the team which has the player who has scored the most goals.
For example, if my table has Team A and Team B, and Team B has the player which has scored the most goals out of every player (in all the teams), then I would like the filter to include only Team B (but show every player in Team B).

This is a good use case for a top filter.
Place Team on the filter shelf.
When defining the filter, choose the Top tab.
Select By field, Top 1, Number of Goals and Max
This tells Tableau to determine the maximum value for the [Number of Goals] field for each Team, and then filter to only include the Team with the top value.
(Note, this approach assumes that there is a single data row per player showing the total number of goals that player achieved. If your data is structured differently, say one data row per player per game, then you might need to revise the approach slightly, perhaps using an LOD calc too)
In SQL, this typically leads to a HAVING clause.
The only downside is if two teams tie for the top position, I believe you will only see one of them in that case.
If that case is important to you, you can get a similar effect using a table calc to rank teams by their max [Number of Goals], setting the tie breaking rule of your choice for the quick table calc, and then using that calc on the filter shelf to only show teams with the top rank. This will show multiple teams if they are tied for top rank.
The table calc approach is more flexible but can be less efficient, especially for large data sets, since the data is fetched from the data source to Tableau for the ranking calculation, and then only some of it is displayed. (Table calc come very late in the processing pipeline) The top filter approach performs the calculations and filters at the data source, and only sends the filtered results back to the Tableau client.

Related

Tableau filter based on multiple parameters?

I have some data like this below
data image see link
I would like to make a dashboard that will show you all the related empires based on what you choose (those that existed at the same time AND those in one of it's regions of influence). For example if I choose Rome then it will only show Egypt, Greek and Gaul and not show Byzantine because it is from a later time and not show China because it is in a different region. See below
See expected result picture in link
The simple way to achieve this task is to "Self-Join"
I would self-join the data again with Inner join on Region and Era
then, to handle the duplicate rows I would create a calculation
[Empire_Data1] = [Empires_Data2]
and put as false in the filter shelf.
then if you drag both Empires field you will the output you are looking for,
Since this is like 20 rows of data, you can perform a self join without any challenge.
But you have a lot of rows as in hundreds of thousands or more then, you might want to prep your data before connecting to the tableau.

How to sum two different group by calculated fields in Tableau?

I have two calculated fields (HomeScore, AwayScore) and I grouped them by different dimensions(Home, Away). Now, I have TotalRuns per Team both in HomeGames and AwayGames. My problem is that I want to find the sum of TotalRuns per Team not separetely for home games and away games. I want to add these group-by fields somehow. I attach a screenshot to see my work. For example first column for both charts is "Arizona Diamondbacks" which has 263 Runs in first chart and 337 in the second one. I want to show the 263+337=600 Runs. Any Idea?
You'll want to create a LOD expression.
{FIXED [Team Name] : SUM([Total Runs])}
Think of your data as a big table (which it technically always is in Tableau). Every grouping, filter, etc. that you do narrows down the number of columns and rows you have left until you are left with your data set that contributes to your chart. LOD expressions allow you to back out of the filters, etc. in your calculation. In this case, you narrowed down to home or away games, and we are backing out of that to get a bigger picture of the data.

How can I create filters on a series of tables where the final table yields a single data observation?

I am creating an interactive 'calculator' using tableau. I have a series of dataframes that I have crossed with one another, such that the resulting dataframe is every possible combination between the tables, and every row is unique.
Each column is its own worksheet as a table. Each table in the dashboard is a pane. So, here we have a series of tables with selectable units of measurement, and the final pane on the dashboard should filter to the cell for its respective column, on the unique row of the dataset that the user has selected and 'filtered out'.
I'm having some issues getting this to work and not sure why.
The closest I can think to solving this would be 'Cascading Filters.' Here are a couple resources:
General Use
In dashboard action-filter form
The critical piece, however, is that the filters must be selected in a specific order - therefore making them 'cascading.' This may differ from your presumed concept of clicking/filtering in any order on the worksheets to then arrive to a final answer. I do think that this may be a limitation of Tableau - I don't think that a 'many to many' type of relationship can be set up within Action Filters.

Using both counts and averages in tableau

I've got some data that I'd like to display both the averages and the count for.
For instance, there are 50 People taking a survey. Their names are saved in a Dimension "Raters". They are taste testing several products. These products are saved in a Dimension "Products"
They answer 4 questions. Taste, Texture, Appearance, Uniqueness, all saved in Dimension "Question"
The actual ratings are saved in "Ratings". This is a measure.
I can very easily make a table with Raters on the Rows, Question on the Columns, AVG(Ratings) in the text.
This shows me the average score for each question the rater answered.
It looks like this:
Rater-----Taste-----Texture-----Appearance-----Uniqueness
Joe---------2.2---------4.3--------------3.7-----------------2.4
Bob--------3.0----------1.2-------------3.4-----------------4.4
Sally-------4.5----------3.3-------------4.5-----------------3.2
Jessica---5.0----------3.0-------------2.0-----------------1.0
So far, so good.
Jessica's results look suspiciously integerish. When I look at the background data, I see that she only answered for 1 product.
I'd like to be able to add a column to the right of uniqueness which is the count of all product responses for that person.
I've played with this quite a bit, and I'm not sure that it is possible. Maybe with LOD?
I'd also like to filter the table, so that only "tough" raters are shown. Criteria for this is: Their average response for at least two criteria should be below 3.0. That would include Joe and Jessica.
When I try to do counts based on averages, I run into the "cannot aggregate an aggregate rule".
Is there a way around this? It would be trivial to do in excel with another column, a countif, and a filter.
Thanks,
Chris
Part 1:
You should be able to create a calculated field(Analysis->Calculated Field) and name it something like "Number of Records". In the query box just set it to 1 and select "Okay".
This new field will be selectable in the measures. Drag it into your table in the columns area and it should add a count next to your averages.
Part2:
In your measure values box you should be able to right click you measures. This will bring up a list of options including "Filter". Select this option.
On the SUM(Number of Records) set it to "At Least" = 2. Then right click on the AVG(Ratings) measure and set it to "At Most" = 3
Put Products on the Rows shelf.
Then right click on that Products field on the Rows shelf and change ITT from a dimension to a measure. Be sure to choose Count Distinct for the aggregation.
Finally, right click on the field again and change it from continuous to discrete.
This shows how many different products each person reviewed, no matter how many characteristics they rated. If you want the number of ratings, use count instead of count distinct. Or just Sum(number of records), again set to discrete

Show calculated measure in row?

I'm using Tableau Desktop 9.0 on OSX. I have data (loaded from a local CSV file) that looks like this:
code,org,items
0212000AA,142,10
0212000AA,143,15
0313000AA,142,90
0314000AA,143,85
I want a chart that shows the number of items beginning with 0212 as a percentage of all items, for each organisation. (I mean as a percentage of the organisation's items - for example, in the above, I would like to show 0.1 (10/(10+90)) for organisation 142.)
I have been able to get part way there, by adding org to Columns, and SUM(items) to Rows. Then by adding a Wildcard filter on code, for starts with 0212.
This shows me the number of items starting with 0212, by organisation.
But what I don't know how to do is show this divided by the value of all items for the organisation.
Is this possible in Tableau, or do I need to pre-calculate it before loading my data source?
One way is to define a calculated field called matches_code_prefix as:
left(code, 4) = "0212"
You can also define a parameter called, say, code_prefix to avoid hard coding the prefix string:
left(code, 4) = code_prefix
And then show the parameter control for code_prefix to allow the user to interact with it.
If you use this new field as a dimension to separate SUM(items) according to those that match the prefix and those that don't, you can then use a quick table calculation to get the percent of total.
For example, you can place org on the Rows shelf and matches_code_prefix on the Columns shelf, and SUM(items) on the Text shelf to make a table. Then under the analysis menu, turn on grand totals for both rows and columns to see the behavior. Next, right click on SUM(items) and choose Quick Table Calc->Percent of Total. Tableau will display the percents of total in the table.
If you want the percent of total defined differently than the default, then right click on the measure again and set Compute Using to a different value such as matches_code_prefix in your case. It's usually better to set compute using to a specific field.
If you only want to display the value for the matching case, select the column header you don't want to see and choose hide. You can also turn off the grand totals from the analysis menu when you are done.
When you are confident in the values in your table, you can turn it into a bar chart for example by moving matches_code_prefix to the detail shelf and the measure to the Columns shelf.
--
The above is the drag and drop approach. If you prefer to hard code everything in a single calculated field that is calculated on the database side, you could instead define a calculation such as:
zn(sum(if matches_code_prefix then items end)) / sum(items)
Then set the default number format for that field to display as a percentage