How to filter top customers within certain section in Tableau - tableau-api

I have a Tableau file whose source is from one Excel sheet as shown below:
And it's how it looks in Tableau:
I have a Tableau sheet to show me the top 3 customers in each section. For example, company F, H, J, B, A are in section XXX, I filter section XXX only, sort F, H, J, B, A, select the top 3 customers and hit "keep only". So I have a table of top 3 customers in XXX section. Please see the pics below:
My question is, every month I have an updated Excel sheet with same format and I feed it into Tableau, the sales change every month but I always want top 3 customers in each section. For example, top 3 customers this month in XXX section are F, H, J but next month it might be A,B,H. However since I use "keep only" to filter F, H, J, the top 3 customers can only be F, H, J unless I manually change the filter. Is there anyway I can program Tableau to pick up the top 3 automatically whenever I feed new data to this file? I know "filter top n by" can do it but it can only filter by one variable, like they can only filter by sales instead of sales AND sections. I want to use "by formula" in the pic below to do it but I am not sure how to write the formula.

Have you tried to use the "Top" instead of "Condition" tab? You could also try to use a rank.
Create a calculated field "Rank", put index() into it, make it discrete and put it between your segment and customer pillow. Untick "Show header" and use it as a filter on the filter shelf.

I would use the Quick Table Calculation Rank. To do this create a new worksheet as follows:
Drag Section onto Rows
Drag Customer onto Rows
Drag Sales onto text mark
Drag sales onto detail
Right click the sales that you have dragged onto detail. Select Quick table calc and then rank.
Change this table calc from the detail mark onto the rank mark.
Now you can see what it is doing my default. You can see that is will be calculating the rank across all sections. As you mentioned you want the rank per section you just need to adjust the way the quick table calc is working. To do this right click on the measure and select edit table calc. Under Compute using you can change the way the calc is working. Select a couple of different ones to see what is happening. As you have structured the workbook to have Section and then Customer on the Rows shelf you should be able to use pane across then down. This means that it will calculate the rank per pane which in this case is per Section and will calculate down across Customer.
8) You can now drag this measure onto the filters pane and select a range of 1-3 this will filter the view to only show the top 3.
This method will work dynamically even when the data is updated :)

Related

How to create a dynamic column (bar) graph in calc/excel

I have a table with 6 columns and need make a graphic dynamic equal this other picture. Basically horizontally I would like to have the months and vertically the total. And in the filters you could choose between the other columns. Just that, but it's been impossible for me
I really don't know what else to do to be able to develop a dynamic graph like the one I made on paper ... I have the file, with the table, but I can't develop the graph at all. Can someone give me a tip on how to make it the same?
Generally, you can create a dynamic chart in LO Calc using a Pivot Table. I'll show below how to do this for a data table with a structure like yours. Please notice that I'm not 100% sure about the resulting chart's layout. I assume it should display bars for the %COM and the %VAL values for each month (defined by COMPET) for a given UNI.
I'm using the following simplified data source containing arbitrary values, but with the same structure as yours:
1. Create a filtering pivot table:
Select your entire source table;
Menu Data -> Pivot Table -> Insert or Edit...
In the "Select Source" Window: "Current Selection" -> OK
Define the pivot table layout by dragging the fields from "Available Fields" to the appropriate layout fields:
a. "UNI" to "Filters";
b. "COMPET" to "Row Fields";
c. "%COM" and "%VAL" to "Data Fields";
d. Open "Options" and select "Add Filter"
e. Under "Source and Destination", set the desired destination (new blank sheet or anything else).
The dialogue shot now look like this (arrows added to illustrate the steps above):
The resulting pivot chart should look like this (don't worry about the values. Since there's currently no filter applied yet, the pivot chart simply sums the values from every "UNI" for each month):
2. Insert a column chart based on pivot table
Now, simply create a simple columns chart with bars from the pivot table: Select the data area including headers (in my example: A5:C9) and create the chart without any modifications. The resulting chart is shown below.
Notice the filter Combobox in the upper left corner, currently labeled "UNI | - all -" (the filter column and the current filter value). LO Calc inserted it automatically since the Pivot Chart contains a filter on the UNI column. The filter ComboBox works the same way as the AutoFilter. Again, don't worry about the values shown since there's still no filter applied (thus, it shows "- all -" instead of the filtered UNI value):
Now, you can use the filter ComboBox for the UNI value in the chart to restrict the chart to a certain UNI value. Notice that the ComboBox values changes from "UNI | - all -" to "UNI | B", since there's an active filter on "B" values from the UNI column:
3. Add a secondary Y axis
Since the two values (COM and VAL) are quite different, a secondary axis may be useful. To add one, do the following:
Make sure you're still in chart editing mode (check if there's a thick gray border around the chart. If it isn't, double-click into the chart area to enter editing mode; alternatively, right-cluíck into the chart and select "Edit" from the context menu).
Right-click inside the chart area and select "Insert/delete axes";
Under "Secondary axed", tick "Y axis"; click OK. A secondary axis should appear.
Right-click into one of the value bars, select "Format data series";
Under "Options", "Align data series to", select "secondary Y axis"; under "Settings", select "Show bars side by side"; click OK.
Voilá:
That's all - now you have a sheet with a dynamic chart based on the selected UNI value(s).

Tableau - Similar function to SQL Group by

I have recently started using Tableau but am still very new to it. I don't know enough of the Tableau vocabulary to be able to find this answer through brute force googling. Hopefully some one here can help point me in a good direction.
I have a simple table of data, containing the columns and types: Date (Date), ID (Numerical), and Status (Text)
I want to be able to generate a report that has: Date, and Percent of the IDs on that date where the Status is "Complete."
In SQL I could do this by running a query along the lines of:
select date, (count(status like "Complete")/count(status)*100) from table
group by date;
Where can I look for this in Tableau? I tried creating a new Calculated measure in the sheet I am working on, but I couldn't find any built in functions that would add this ability. Thanks for any assistance.
So this should be pretty easy. In your tableau screen(when in a sheet) on the left you will see a column which is broken into two. On the top are the "Dimensions"(these are the things you will organise your data on, usually strings or dates) and on the bottom are the "Measures"(these are integers).
So under dimensions you should see "Date" and "Status". In the Dimensions you should see "Number of Records" and "ID"(this is your variable, you can convert it to a dimension by right clicking and selecting that option).
So what you need to do:
You just want status = complete, so drag your "Status" field into the Filter box(just to the right of the dimension column). You will get a pop up of the different types, select "Complete".
This has filtered your data source for only complete rows.
Drag you "Date" field to the "Rows" shelf, on the top of the screen. This will default to the Year of the date.
It will automatically go to a bar chart, change it to a table by selecting "Show Me" on the top right and select the table icon.
Double click on your "Number of Records" measure. This will add it to your sheet. This will now be auto summed per year.
To convert it to % of, right click on the measure in the Marks window(it should look like a green box "SUM(Number ....)"). Right click and select the option "quick table calculation", here select "Percentage of Total".
You will now have the % total per year for all records where status is equal to correct.
(Optional) - To adjust the date dimension, right click on the "Date" Pill(its up the top in the rows shelf). Hear you can see different options for quarter, month, day. You can change it to any of these or a custom data format.

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.

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

Top N in Cross Tab base on Column

I have using Cross Tab in my report. The column is the Activities. The rows is the user name. The row will show the number of time the user attend those activities. How i can create a top N to show which activities has the most attendance? Please help.
Thanks
If you want to leave the Cross-Tab you have alone, then my suggestion would be to just add another Cross-Tab to the same report section that only has every activity summarized by row as counts of attendees. You could then restrict that CT to only show the Top-2 activities (By going to Group Sort Expert -> Sort by Top N -> N=2). You could even suppress the fields you don't want to show and hide the grid lines so that only the top 2 activities are actually spelled out.
An alternative is to pivot your original CT so that each row was an activity instead of a user, and then sort by the attendance in descending order. This would make it obvious which activities were the top 2.