Tableau: Plot percentage of binary column - tableau-api

Simplified example: column of 'measure' data is binary 0's and 1's. The sum of the column (all the 1's summed) is 3948. The length of the column is 4567. 3948 is 86% of 4567. How do I create a bar chart showing this percentage. All I can get is a bar adding up to 100%.
I've tried absolutely everything in the percentage of dropdown, calculated fields, online tutorials, etc.

Two approaches:
Right click on your measure field on whichever shelf you placed it. Choose Quick Table Calc -> Percentage of Total. Experiment with different settings for "Compute Using" and read about addressing and partitioning of table calculations to learn how to specify percent of "what".
Or create a calculated field specific to your problem defined as below:
sum(int([my measure field] = 1)) / count(1)
Be sure to set the default number format for your calculated field to a percentage, by right clicking on it in the data pane (left margin) and revising the default properties
Note, the second calculation works because the INT() function converts True to 1 and False to 0, which is useful in several contexts.

You can go about this using the following method
Add 'measure' to Columns and make it a Discrete Dimension
Add SUM(Number of Records) to Rows. This should give you the bar chart you need.
This would help achieve what you are looking to do. For more customization and a better look for the graph you are looking to build in Tableau.
Add 'measure' to the colour legend and make it a Discrete Dimension.
Add SUM(Number of Records) as a Label and do a '% of Total' quick table calculation.

Related

Percentage of total changes on applying filter

I have a data table with three dimensions and one measure. For each row, I am trying to calculate the percentage of total (calculated by taking the sum of rows) using a calculated field.
As seen in the screenshot attached, For the column titles 'Dec-19' I want the values to be a percentage of current value / grand total (calculated at the bottom as 122,187)
Screenshot of DataTable:
So e.g. for the Column B value of 2000, the Dec-19 column should be (97/122,187) * 100 = 0.079.
I have achieved this by creating a calculated field with the formula: SUM (sales) / MAX ({EXCLUDE (Column B): Sum (sales}), where sales is the measure used in the datatable.
However, upon application of filter on column B, the percentage value changes. e.g. if I select the value 2000 in my filter for column B, I get the percentage as 100%. It seems as if the percentage is being calculated based on only the rows in the filter.
Since you haven't included any sample data, I created some sample data like this, hope this resemble yours.
Thereafter, I built a cross-tab view in tableau, somewhat like yours
If that is the scenario, use a calculated field, say CF like this, instead of yours
([Sales])/
{FIXED [Col1], DATETRUNC('month', [Col3]) : sum([Sales])}
Dragging it in the view
and thus, filtering won't affect your calculation

How to apply a filter to only one column? The columns differ by a value of the same binary filter

I have visualizations that have bar graphs set up in 6 separate sheets. These bar graphs need to go side by side for comparison. 2 graphs will be combined to form one side-by-side graph. They only differ by a filter that is set to either 0 or 1 in the corresponding sheets. Everything else is the same.
Example:
In sheet 1, XMJ is filtered by Misdemeanor = 0
In sheet 2, XMJ is filtered by Misdemeanor = 1
I'd like to make them show side-by-side for comparison.
I have already tried duplicating XMJ and bringing it side-by-side but couldn't apply Misdemeanor = 1 or 0 separately to the duplicate column.
Here is the file: Visualz
You can accomplish this with a table calc filter.
Create a calculation lookup(min([Misdemeanor]),0) and put it on your filter shelf in each sheet and you can filter them independently.
Table calcs happen after the data is displayed on the viz (see Order of Operations).
The min([Misdemeanor]) part tells Tableau you want to look at the minimum value (this could be also max/attr/sum it wouldn't matter in your case).
The lookup(measure,0) tells Tableau to look at the current row of the measure (but again, after the data is already on the table). At this point, you can filter it independently.
EDIT: Another thought is you might just have the filters set to All Using this Datasource or (multiple) selected sheets. You can change this behavior in either the worksheet (1st picture) or dashboard (2nd worksheet).

Get average value of each (Sub) column

i would like to calculate the average of values of each "main" column, as shown in the picture (named as bundling column). Each bundling(main) column has 1 to N "sub columns" (which are values for a certain datetime). The bundling itself is variable, it changes for different filters.
How can i reference to these sub columns to get the sum/count and average of these? I thought of using the "Window average" function but i don't have an idea how to define the start/end offset parameters. Not sure if window average is the correct option.
Thank you very much
A level of detail (LOD) calculation will allow you to control at what level the aggregation occurs.
{INCLUDE [Agg(Bundling)]: AVG([Agg(Error Select)]}

How to calculate MARGIN in Tableau

I'm trying to calculate margin as usual but Tableau would not calculate simple fraction and as a result of calc shows 0.
Here is how I'm doing to get the result
IF [Scenario]="(Fact)"
Then (([2.1.4. Sales]+[3.1.5. Cost)/[2.1.4. Sales])
END
What am I doing wrong?
I suppose the problem is that the calculation uses wrong Number Forrmat.
You need to do the following
Right click calculation in measures bar
Select Default Properties -> Number Format ...
Choose Number (custom)
Click OK

Tableau Calculated Field Filtering

I am struggling with Custom Filter using Calculated Field.
Below is the screenshot of the same visualized chart.
What I am struggling is to create a filter where I can give a scale of Correlation, example - I want to show all the age groups and Ethnicity where the Correlation value is between 0.6 and 0.9
I am able to bring in one Measure Value and as you can see, the filter slider is there. But I need that filter to work on all the fields and not just one value. Like a Universal Slider for all the values.
Please help.
You cannot set one filter to be used on several measures. However what you can do is create two parameters and use them to filter each measure in relation.
create 2 parameters minCorrelation and maxCorrelation with values between 0 and 1 and stepsize of 0.1 (or whatever granularity you need)
open one of your filters and go to formula, use a custom formula like [0-17] > [minCorrelation] AND [0-17] < [maxCorrelation]
repeat that for every measure and the filter will adjust when you change the values for your parameters.