Restricting tableau filter options without changing underlying data or display - tableau-api

I am looking for a way to restrict the filter options on a dashboard without changing the underlying data or display.
For example, with a dataset of
Company A: 10 units.
Company B: 5 units.
Company C: 2 units.
I would like the Total Units to display as 17 when no filter is applied, however I would only like to show 'Company A' as an option in the filter.

I can't see your data, so I'm approximating the column names and values. You'll have to adjust these on your end.
Create a parameter, like CompanyFilterParameter, with the values 'Company A' and 'All'.
Create a calculated field to use as your filter, CompanyFilter:
[CompanyFilterParameter] = [Company] OR [CompanyFilterParameter] = 'All'
Put [CompanyFilter] on the Filter card and set it to true. Finally, add your parameter control to the sheet (right click [CompanyFilterParameter] and select "Show Parameter Control").

Related

Filtering Based on a Different Column on Tableau

I'm wondering if something like this is possible.
Assume I have a data table like this:
I want a filter, where user picks France for example, but the data is filtered based on corresponding Continent value, e.g., all Europe records should show up.
Is this possible?
Sure, We can do that. If you add country to Filters shelf, Tableau will show only records of selected value. In our case, if we filter "France", Tableau shows only records which has France. So we will miss other Europe records. Parameter can handle this scenario. Follow below steps.
1.Create a String parameter
2. Create a calculated field
3. Add the created calculated field to Filters shelf then choose 'show'
4. Right click parameter then 'Show parameter control'. So it will works like filter
Method 2: Dynamically change parameter value
Pros: No hard coding, dynamically changes value based on selection. It works, well on dashboard
Cons: You will not have drop down for selection like filter. So, you need to click a chart to trigger the changes.
1. Create a String parameter with allowable values as 'ALL'
2.Create a calculated field
3.Create a parameter action in dashboard.
Dashboard-> Actions-> Add Action -> Change Parameter
In Change Parameter dialogue box, set target parameter as 'Parameter Name' and value field as 'Continent'
4. Add the calculated field to filter and select 'True' on other sheets
5. Final Dashboard looks like
Click the icon on the selector sheet. It will automatically filter data on data sheet.
Inside the selector sheet

Count of group dimensions item in Tableau

I'm fairly new to tableau and I'm having the following issue. Below is a sample of the data I'm using.
Customer No | Item
___________________
1 A
1 B
2 A
3 A
4 A
4 B
5 B
6 A
I'm trying to get a count of how many customers bought Item A and B. So far I tried doing a separate group by combining A and B but I get the total result of 8. I also tried doing a calculation and I'm getting the same result of 8. Can someone please point me to the right direction on how to get this result. Thanks!
This is the result I'm trying to get:
Item| Count
A 5
B 3
A and B 2
I recreated your exact dataset and pasted it into Tableau so you could see a couple of examples.
Here's how you can see the number of customers who purchased an individual item, plus the number of customers who purchased both items.
Your calculation will be:
IF { FIXED [Customer No]: COUNTD([Item]) } = 1 THEN
[Item]
ELSE
'Both A and B'
END
And you'll need to set your view up to look like this:
Below are ways you can see when both items were purchased.
Boolean OR
The calculation you'll want to use is:
ATTR([ITEM]) = 'A' OR ATTR([ITEM]) = 'B'
And you'll want to set up your view to look like this:
A, B or Both
If you would like a bit more specificity in your result, you might try:
IF ATTR([Item]) = 'A' THEN
'A'
ELSEIF ATTR([Item]) = 'B' THEN
'B'
ELSE
'BOTH'
END
Replacing the previous calculation with the new looks like this:
More than 1 item
If the specific items purchased don't matter, you could use this logic.
COUNTD([Item]) > 1
Replacing the previous calculation with this one would look like:
More than 1 Item using a window function (probably overkill)
The calculation you'll need to use is:
WINDOW_COUNT(COUNTD([Item]))
Because this is a Window function, we'll need to specify how it's calculated across our dimensions. To do this click the down arrow on the right-hand side of the pill and select Edit Table Calculation...
You'll then need to set these settings:
I'll add the calculation we created in the first example ([A and B]) to the filter shelf and select True. That should give you something that looks like:
More than 1 item using a Level of Detail expression
The calculation for this example is:
{ EXCLUDE [Item]: COUNTD([Item]) }
You'll view should look like:
As you can see Tableau is quite flexible. Hope these examples were helpful!
You might want to use Tableau’s set feature to approach problems like this.
For example, right click on the field [Customer No] in the data pane (i.e. left sidebar) and choose the “Create Set” command. Click “Use All” at the top of the set panel and then click the Condition tab. Define the set using the condition MAX([Item] = “A”). Name the set “Customers who bought A”.
Similarly, create a set of customers who bought item B. You can then select both sets in the data pane, and create a combined set to be the intersection, that is, customers who bought both an item A and an item B.
You can think of a set as either a mathematical set of the members of a field that belong to the set (i.e. a set of customer ids) or as Boolean function defined for each data record in the data source indicating whether that data record is associated with the set (i.e. a Boolean function that operates on transactions to say whether the associated customer ID is in the set. A key to keep in mind for the condition formulas used here is that the condition is an aggregate formula, operating on a block of data records for a customer ID to determine whether the customer ID is in the set.
Once you have defined your sets of interest, you can use them in many ways - in calculated fields, as filters, as dimensions on shelves in a visualization, in set actions, to combine with other sets ...
To define a measure that counts the customers in a set, create a calculated field such as “[Num A Customers]” as COUNTD(if [Customers who bought A] then [Customer ID] end) Do the same for whatever other sets you are interested in. Then you can use those measures (probably with Measure Names and Measure Values) to make your viz.

Graph based on the user filter selection

On a tableau dashboard there are 2 filters and a bar graph.
The filters are 1. to select top or bottom customers
2. how many ex:5,10,15 etc
when the user selects top and 5 in the respective filters then top5 customers have to show in the bar graph.
if the user selects bottom ,10 in the respective filters then bottom 10 customers have to shown in the graph.
how to achieve this when the data contains only customers details and their billing amount ?
Instead of filter, you can go with the Parameter for getting the result. I have done the top and bottom multiple times in many of the tableau visualizations and its so easy.
Below are the steps to achieve your requirement.
Create a parameter that will allow you to select top and bottom
Create another parameter that will allow you to select the desired numbers like 5, 10, 15 etc.
Here i have created a parameter that will have values from 10 to 50 in a step size of 10.
Create a calculated field that will subset data based on the parameters chosen
In the above screenshot, I am using the top site parameter and creating a conditional statement that will show the states based on the value chosen in the site parameter and the value for that state.
Put the calculated field in the filter and select show and click ok in the filter box.
Now the view will show the top count based on the value selected in the parameter.
Please note the calculation is for top N and for bottom N you need to change the calculation.
Hope this will help you. I can provide you a workbook if you need.

Compare one subgroup vs all others in user-friendly way

I want workbook readers to be able to select different values of a variable to change a chart comparing that subgroup vs. all others grouped together.
For instance, using the Superstore sample data, I can create this chart comparing the percentage of sales by category, by region:
I want the user to be able to specify a region and see a comparison of that region's sales distribution vs. all other regions combined. For instance, I can create a calculated field to group into Central. vs all others, using:
IIF([Region] = "Central", "Central", "Others"), which I can use to make this chart:
But I want the user to be able to specify the region to compare (Central, East, South, West) to others. This approach hard-codes the comparison. How can I make this something the user can click around on to explore?
I would first create a parameter, specifying "Allowable values" = "List" and then using "Add from Field" and selecting Region, like this:
Right-click on the parameter (I called it RegionCompare) and select Show Parameter Control. The user will then be able to click around.
Then create a calculated field called Selected_Region defined as:
IIF([Region] = [RegionCompare], [RegionCompare], "Others")
Then place Selected_Region on the Rows shelf and you'll be all set.

Math operators parameters

I wanted to know if we can use math operators in the parameter of the report.
I have a parameter called "EMP_Attendance".
I want to have the parameter to display and Run the report with values
Parameter:
EMP_Attendance
= 100.00%
<100.00% and >=90.00%
<90.00% and >=80.00%
<80.00%
the Report should run according to this value
This is not natively possible but there is a slight work around.
Create a visible parameter with your four options above.
Create two internal parameters that are populated by two dummy sqls, one lower and one upper.
Make the queries produce the appropriate upper and lower limits based on the users selection, e.g. If 100% is selected lower = 100 and upper = 101.
Filter the dataset by these two limits.
First you would add 4 available values to your parameter with a label of "100%" etc. and values of 1,2,3,4.
Then you have 2 options to filter.
You can add something like this to your query:
SELECT case when EMP_Attendance = 100 then 1
when EMP_Attendance <100 and EMP_Attendance >=90.00% then 2
when EMP_Attendance <90 and EMP_Attendance >=80 then 3
else 4 end as AttendanceGroup
WHERE AttendanceGroup = #AttendanceParameter
The other option is to keep the query as is so that it returns all the data to the report. Right-click on the table and go to its properties. Go to Filters. Add filters here to compare your parameter with the EMP_Attendance value.