How do I sort this scatter plot? - tableau-api

I would like to sort this scatter plot, which is summarized with a Band that includes Minimum, Average, and Maximum.
I would like to sort it in 2 ways:
by Average
by Widest Range (ie difference between Minimum and Maximum values)
Tableau Public workbook
If you can't view this or I'm not allowed to post external resources on stackoverflow, then perhaps you can show me on this screenshot what I would click to get started on the following sort
Also, bonus question, is there a way to create a control for the user to toggle between the 2 sort methods in the same chart? Or do I have to duplicate the chart with a different sort type for each?
One note is that I only have Tableau Public version since I'm evaluating the product. Until I get a paid version, I can't open a workbook file unless you publish it to Tableau Public cloud. But rather than give me the workbook answer, I would just appreciate it if you gave me instructions to do this as this is more of a learning exercise.
Thanks!

Somewhat unfortunately, you'll have to replicate the min,avg,max by creating 3 calculated fields. Tableau cannot operate on the values placed on the view via reference lines.
These calculations might look something like these:
{Fixed [Cwe]: Min([Cvss Score])}
~
{Fixed [Cwe]: Avg([Cvss Score])}
~
{Fixed [Cwe]: Max([Cvss Score])}
In general, from there, you should pretty easily be able to apply them to the view and sort. Average will be easy. The difference between Min and Max will just need a subtracting calculated field to sort by. Once they're on the view, I'd put them as a dimension (column) to verify that the numbers look correct.
Take note that LOD calculations take place before filtering, so you'll want to put the Cvss filter you have there 'on context' by right clicking it and clicking 'add to context'
Here is how I would complete the sorts:
Starting with all the above calculations on 'Rows' and ensuring that they are 'Dimensions' (Blue).
After right clicking "Sort..." on [Sub-Category] on 'Rows'. Select which field to sort by.
From there, the calculated fields can be taken off the rows column. (They were only there in the first place to ensure that you could check that the sorts took place. They don't actually need to have been there in the first place.)

Related

Form data evaluation

I have a form data wherein tableau I am using the below value to find out the choices for a multiple value question. The question is Could you please indicate one or two areas where we fell short.
the value can be explosives, vehicles, cement etc
I have individually accounted for each of the choices in the below calculated field:
int(contains(lower([Could you please indicate one / two of the following areas where we fell short of meeting your expectations?]),'factory'))
Similarly I have found out for other values:
The calculated fields are hasvehicle, hasfactory etc
But the problem is how can I visualize the same in the form of bars?
All I am able to do is this:
How can I visualise the same in the form of bars side by side?
When you have one measure on Rows, drag the second measure and drop it in the axis.
It will result with Measure Names on the Columns shelf and Measure Values on the rows shelf.

How to sort by any measure in a Tableau table

I've built a new worksheet that has two dimensions and several facts. When I try to sort on any column, it only seems to sort within the dimensions. Is it possible to sort based on the column, ignoring dimensions? I find if I concatenate the two dimensions into one... that does work, but is not ideal.
Ah yes, sorting in Tableau. Took me a long time to understand it. It doesn't do sorting the way you would expect in other tools like Excel. This is because it's grouping dimensions from left to right. Think of each dimension getting nested inside the one to the left of it. Another way to think of it is that Tableau doesn't sort measures, it sorts dimensions based on some value a measure. That's why concatenating dimensions will yield the expected result, because you have just one calculated dimension and that dimension gets sorted by the value of a measure. You can right click on the concatenated dimension in your Rows shelf and choose Show Header. That's probably your best bet.
See this article from The Information Lab on the sorting in Tableau: https://www.theinformationlab.co.uk/2014/11/03/understanding-sorting-tableau/
There are some Tableau Community posts about it too.
https://community.tableau.com/thread/118958
https://community.tableau.com/thread/221956
https://community.tableau.com/thread/164714

Tableau Dual Axis with different filters

I am trying to create a graph with two lines, with two filters from the same dimension.
I have a dimension which has 20+ values. I'd like one line to show data based on just one of the selected values and the other line to show a line excluding that same value.
I've tried the following:
-Creating a duplicate/copy dimension and filtering the original one with the first, and the copy with the 2nd. When I do this, the graphic disappears.
-Creating a calculated field that tries to split the measures up. This isn't letting me track the count.
I want this on the same axis; the best I've been able to do is create two sheets, one with the first filter and one with the 2nd, and stack them in a dashboard.
My end user wants the lines in the same visual, otherwise I'd be happy with the dashboard approach. Right now, though, I'd also like to know how to do this.
It is a little hard to tell exactly what you want to achieve, but the problem with filtering is common.
The principle that is important is that Tableau will filter the whole dataset by row. So duplicating the dimension you want to filter won't help as the filter on the original dimension will also filter the corresponding rows in the second dimension. Any solution has to be clever enough to work around this issue.
One solution is to build two new dimensions that use a calculation rather than a filter to create the new result. Let's say you have a dimension, [size] that has a range of numbers from 1 to 10 and you want to compare the total number of rows including and excluding the number 5. You could create a new field using a formula like if [size] <> 5 then 1 else 0 end
Summing the new field will give a count of the number of rows that don't contain a 5 and this can be compared directly to a rowcount of the original [size] field which will give the number including the value 5.
This basic principle can be extended to much more complex logic. The essential point is to realise that filters act on every row in your data and can't, by themselves, show comparisons with alternative filter choices on a single visualisation.
Depending on the nature of your problem there may be other solutions worth looking at including sets and groups but you would need to provide more specific details for users here to tell you whether they would be useful.
We can make a a set out of the values of the dimension and then place it in the required shelf. So, you will have your dimension which will plot accordingly and set which will have data as per the requirement because with filter you can't have that independence of showing data everytime you want.

Require minimum number of data points before plotting a point in Tableau

Can I cause Tableau to require a certain number of underlying data points before plotting a point on the graph?
For example, here's a graph showing average moods over the course of the day on Tuesdays:
There's nothing uniquely awful about midnight on Tuesdays, it's just that there's only one data point for that particular time, and it's an outlier. Is it possible to have the graph show midnight as missing unless there are more than (for example) three different records from midnight being averaged together?
You could define an aggregate calculated field, called say avg_mood as:
if count(Mood) >= 3 then avg(Mood) end
Since the aggregation is hard coded into the calculation, Tableau will display AGG(avg_mood) for the field on any shelves you use it on, rather than letting you toggle the aggregation outside the formula as it will for other measures.
Note, there is no else branch, so the calculation will evaluate to null if there are less than three non-null Moods in a partition of data rows (based on the dimensions)
You can control how null values are displayed in a line chart. On the format pane, select the field in question from the pull down menu by the word Fields at the top right of the format pane, then select the Pane tab, then at the bottom of the format pane, adjust the Mark settings in the Special value section.

Aggregate bins in Tableau

I want to aggregate bins in tableau.
See the following figure:
I want to aggregate (merge) the NumberM from 6 untill 16 in one category. 5+/(6 and higher) for example and sum the values of 6-16 in that category. I think this can be done with a few simple clicks but I am not able to manage.
Thanks in advance,
Tim
There are several ways to classify data rows into different groups or classes: each with different strengths.
Create a calculated field As emh mentioned, one approach is to create a calculated field to assign a value to a new field indicating which group each data row belongs to. For the effect you want, the calculated field should be discrete (blue). If your calculation doesn't return a value for in one case, e.g. an if statement without an else clause, then the field will be null in that case which is a group in itself. This is a very general approach, and can handle much more complex cases. The only downsides are the need to maintain the calculated field definition and that the cutoff values are hard coded and by itself can't be changed dynamically via a control on the view. BUT those issues can by easily resolved by using a parameter instead of a numeric literal in your calculated field. In fact, that's probably the number one use case for parameters. If you think in SQL, a discrete field on a shelf is like a group by clause.
Use a filter If you only want a subset of the data in your view, e.g. data rows with NumberM in [6, 16] then you can drag the NumberM field onto the filters shelf and select the range you want. Note for continuous (green) numeric fields, filter ranges include their endpoints. Filters are very quick and easy to drop on a view. They can be made dynamically adjustable by right clicking on them and creating a quick filter. Its obvious from the view that a filter is in use, and the caption will include the filter settings in its description. But a filter doesn't let you define multiple bins. If you think in SQL, a filter is like a where clause (or in some cases using the condition tab, like a having clause)
Define histogram bins If you want to create regular sized bins to cover a numeric range, such as values in [1,5], [6,10], [11-15] ..., Tableau can create the bin field for you automatically. Just right click on a numeric field, and select Create Bins.
Define a group Very useful for aggregating discrete values, such as string fields, into categories. Good for rolling up detail or handling multiple spellings or variants in your data. Just right click on a field and select Create Group. Or select some discrete values on an axis or legend and press the paperclip option. If you then edit a group, you'll see what's going on. If you think in SQL, a group is like a SQL case statement.
Define a set Another way to roll up values. The definition of a set can be dynamically computed or a hard coded list of members. Both kinds are useful. You can combine sets with union, intersection, set difference operators, and can test set membership in calculated fields. Sets are useful for binary decisions, rows are divided into those that are members of the set and those that are not.
Filters, sets, groups, calculated fields and parameters can often be combined to accomplish different effects.
Most if not all of these features can be implemented using calculated fields, especially if the business rules get complicated. But if a filter, bin, group or set fits your problem well, then it's often best to start with that, rather than define a calculated field for each and every situation. That said, learning about the 4 kinds of calculated fields really makes a difference in being able to use Tableau well.
You can do this with calculated fields.
Go to: Select Analysis > Create Calculated Field.
Then use this formula:
IF NumberM > 5 THEN "OVER 5"
You can then use that calculated field as a filter on the worksheet in your screenshot.
Answering my own question:
With Tableau 9 this can be easily done with the increased flexibility of the level of detail expressions (LOD). I can really recommend this blog on that subject and many more Tableau functions.