Tableau - Toggle between 2 measures by single select filter on one basic text grid - tableau-api

looking to have a basic text grid by month by product, and then have a single filter on only 2 of the measures. For example:
Measures Filter
------------------
[ ] Sales <-- only show this
[X] Quantity <-- and this as options
[ ] Interest (don't show in filter)
[ ] Fee ( don't show in filter)
JAN | FEB | MAR | APR | MAY | etc ...
products
ITEM1 x x x x x
ITEM2 x x x x x
ITEM3 x x x x x
So the user can basically toggle between Sales or Quantity, and whichever they click on will fill out the x by month.
I was able to get this to work for everything except only showing the 2 measures I want to filter for. It only shows all measures for me in the filter and I can't figure out how to hide them.
What I did was
Drag Date to columns
Drag Product and MeasureNames to Rows
Can someone please help me on getting this correct? Any help or guidance is appreciated!

This is not the correct use case of FILTERS. Filters are normally used to filter (read subset) the data (read rows). Say for example If your dataset has 1000 rows/records and you want some report/visual/aggregation on say 500 rows (based on some criteria of course) you have to filter the data. For selection of argument (user based) in some report/viz, etc. Parameters are used.
Your desired example output is also a perfect case of use of Parameters. You may proceed as follows-
Step-1 Create a parameter (say parameter 1) with values as SALES and QUANTITY.
Step-2 Create a calculated field (say CF1) with the following calculation
CASE [parameter 1]
WHEN 'SALES` THEN [sales]
WHEN 'Quantity' then [Quantity]
END
Note: It is assumed that your field/column names in dataset are sales and Quantity
Step-3 Build your view (Crosstab here) with
months on Columns shelf
products on rows shelf
CF1 on text in Marks card (alternatively just double click it)
Choose measure for aggregation of CF1 as desired (default will be sum)
Step-4 right click paramter 1 and click show parameter. (select desired measure for aggregation in crosstab)
VOILA your desired view is complete. Good luck.

There is another options to add to Anil's good suggestion. You can also use Measure Names as a filter. Hide all measures apart from those you want in the filter, then put Measure Names on the filter shelf.
However, this means you can't use the hidden measures from the data source elsewhere, which can be a deal breaker. Duplicating the data source is a way around that limitation.
But if you only want to show the 2 measures and are happy with single select, then choosing the measure by parameter is the better option, as Anil suggests.

Related

how to count occurrences of a value in Tableau?

I have a dataset with dog ids, dog names, and neighborhoods. I would like to display the n most popular dog names for each neighborhood. How can I do that?
I figured how to display counts for each name in each neighborhood, by simply dragging 'Neighborhood' and 'Animal Name' in 'Rows', and 'CNT(Animal Name)' in 'Columns'. But I don't know how to select the top 3 or 4 names for each neighborhood.
I'm going to use Tableau's Sample Superstore dataset to walk through one way you can show the top N number of Products by Category. This example will easily transfer to Dog Names by Neighborhood.
I'll start by creating a Tableau calculation we'll use as a filter later.
RANK(COUNT([Product Name]))
I'll then put the Category and Product Names dimension on the Rows shelf and the Count of Product Names on the Text marks card.
We'll then place our Production Popularity table calculation on the filter shelf.
When the dialog box appears, just click OK.
Now we need to edit how our Table calculation runs to get the Top N Product Names within each Category.
Select Specific dimension and then uncheck Category or Neighborhood in your case.
Now we need to go edit our filter.
For this example, I'll set the upper limit to 3.
Click OK and you should see the top 3 Product Names by Category.
Of course, you'll want to adjust this example to fit your data.
Hope this was helpful. Happy vizzing!

Tableau - Name Rank, by State / Year / Gender

I have a data set downloaded from the Social Security website. The data is in the form below, and contains the popularity (i.e., as defined by Count) of names, by gender, year and state:
State Gender Year Name Count First Letter
AK F 1910 Anna 10 A
AK F 1910 Annie 12 A
AK F 1911 Annie 6 A
AK F 1912 Alice 5 A
AK M 1912 Wilbur 7 W
AK M 1912 Thomas 7 T
Within Tableau, I'd like to Top X names by each of these categories (or all if not filters are applied). However, when I use a Top filter in a visualization, the underlying data produced by the filter is the form:
For example, I need the first ranked name, and be able to use filters to see how that changes by year, gender, and state. I'm thinking this might be accomplished by an LOD expression, but not sure where to start.
You can achieve this without needing a LOD calculation. Simply change your filters from standard blue dimension filters to be context filters. To do this simply right click on the filter when it is in the filter pane and click "Add to Context". The filter will be shown as grey. Now all ranks will be calculated after filters have been apllied
Why does this work? It is to do with the Order of Operations in Tableau. A calculation such as rank is a table calculation. As the name implies the calculation is processed on the entire data table before dimension filters are applied. However, when something is a context filter it creates temporary tables which are then used to calculate table cals.
Find out more here: https://www.google.com.au/search?q=order+of+operations+tableau&oq=order+of+operations+tableau&aqs=chrome..69i57j0j69i65j0j69i65j0.3475j0j7&sourceid=chrome&ie=UTF-8

Pick group totals, grand totals and normal summarization in Tableau

I am trying to calculate average of 2 columns in another column in Tableau but difficult part is grand total is not getting average instead it is the sum of 3rd calculated field.
A B Calculated field
10 5 2
6 3 2
T 16 8 4 (Here I should get 2 instead it is taking sum of column)
Here I am unable to write separate formula for row totals and grand totals, Only one formula (Calculated Field) is allowed and when I am dragging on sheet it is by default aggregating to sum.
Note: I am expert in Crystal and BO but beginner in Tableau.
Update
Code used for LoD
{FIXED [Product Category]: AVG([Sales])}
Below image is what I got after implementation I have tried with 2 columns but the result is same if I use only one column (I am trying to get the average of sales)
You are almost there - the Grand Total by default does a SUM function you just have use the Total All Using --> Average option.
Output : Level wise SUM(Profit) later averaged across columns and rows. (Show Column Grand Total & Show Row Grand Total active)
Update: Answering the question below. To get the Row-wise avg (which is Cat1-vag in this case) you could just drop the measure and change it to AVG(). Since you needed in a Calculated Field you could use a Simple FIXED LOD. You can also uncheck aggregated measures from Analysis dropdown and have no Dimension in column or row like unlike what this example shows and still get three different averages. Cheers.
{FIXED [Cat1]:AVG([Profit])}
Check out this very smart work around from Joe Mako.
https://community.tableau.com/thread/112791
create a calc field like:
IF FIRST()==0 THEN
WINDOW_AVG(SUM([Sales]),0,IIF(FIRST()==0,LAST(),0))
END
duplicate your Category field
place "Category (copy)" on the level of detail
set the compute using for the calc field pill to use "Category (copy)"
The window function in the calculated field only takes into account what's in the view, and aggregate based on those number.

Counting and finding sum of combination of Dimensional attributes

Got a field in Excel:
Treament Status
IT
IT
SD
USD
SD
SD
USD
I need to use a calculated field to find a Percentage of total using this mathematical formula, based on the number of times certain dimensional attributes appears in the column i.e. Count:
% of R = [Count(SD)+Count(IT)]/[Count(Total of everything in Treatment Status)]
I know how to use the COUNT and SUM functions but I'm trying to connect the dots here.
One simple approach without writing any calculations is
Put Treatment Status on the Row shelf (double click should do it)
Number of Records on the Text Shelf (double click on it for a shortcut)
Then right click on the Number of Records field on the marks card and select Quick Table Calc -> Percent of Total
If you want to combine the SD and IT rows, select both SD and IT, then use the paperclip icon to group them together
The effect is to generate a query like select count(1) from xxx group by TreatmentStatus, and then to compute the percentages in Tableau acting upon the query results.
You need the TOTAL function. This should do it.
% of R = [Count(SD)+Count(IT)]/TOTAL(COUNT([Treatment Status]))

Does Window_SUM really sort the data in Tableau?

Does WINDOW_SUM actually sort the data? what if my table looks like this
userid | price
1 | 5
2 | 6
3 | 7
1 | 10
and say I need the output like below (just one column)
total_price_by_user
15
6
7
clearly I need a sum distinct as a calculated field so I can do the below but I wonder if window_sum actually sorts the data or not and the userid should not be displayed in the output so it should exactly look like above?
WINDOW_SUM(IIF(ATTR([userid])==ZN(LOOKUP(ATTR([userid]), -1)), 0, [price]))
You are working too hard.
Just put make sure Userid is a discrete (blue) dimension and then place it on a shelf, such as the Rows shelf. Then make sure price is a continuous (green) measure and place it on a shelf, such se the Columns shelf. Tableau will aggregate the data and display the sum of all the price values for each user id.
To change a field from dimension to measure, simply drag it to the appropriate section in the data pane on the left (i.e. the pane showing all the field names)
If you want Tableau to sort your users by sum, click the sort button in the toolbar.
Save table calculations like Window_Sum() and lookup() for the occasional special cases that the simpler approaches don't cover.