Are you asking for a way to do this inside Tableau, or in your data source?
Ideally, you'd want the data shaped such that you have a column, like "Quantity", and another column, like "Fruit":
Quantity Fruit 1 Apple 2 Orange 4 Apple 1 Banana 4 Orange 2 Banana 5 Apple
So, what is your data source? Are you experienced enough to re-shape the data?
Sorry for the late reply! I would preferably do it in Tableau itself.
Ideally, I would indeed like to create a dimension: Fruits. The reason for this is that I would like to filter them per fruit type, and have a possibility to calculate percentage of each fruit type towards total Fruits. After that I would like to create a graph with the percentages.
At the moment, when I choose the option to calculate the percentage of different fruit types of total, for each fruit type I get 100%...
And it should be e.g,
Do you know how to make that possible?
Would be happy if you could help me!!!
Fruit example.twbx 7.1 KB
I am not sure how you'd create a dimension called "Fruit" without reshaping the data. If we could refer to "Measure Names" or "Measure Values" in calculations, then this would be possible. Then, we could write something like: IF [Measure Names]="Apples" then "Apples"...
However, we cannot do this. So, in your workbook I simply calculated each % of total manually by creating calculated fields like: Apples %: sum(Apples) / (sum(Apples)+sum(bananas)+sum(oranges)) And used these calculated fields to represent your percentages on a typical bar chart. The percentages are a bit different from what you were expecting... but I believe they are correct. Let me know if this is acceptable.
The resulting view is:
Fruit example ML 8.0.twbx 10.7 KB
1 of 1 people found this helpful
What I have concluded by your query is that you want to calculate the % of total for each fruit by selecting a fruit from filter. If answer is yes then create a parameter like below: -
then create a calculated field with sum of all the fruits(I named it as "Total Fruits") : -
Create another calculated field with following formula: -
if [Choose Fruit Type]=='Apples' then sum([Apples])/sum([Total Fruits])
else if [Choose Fruit Type]=='Bananas' then sum([bananas])/sum([Total Fruits])
else if [Choose Fruit Type] == 'Oranges' then sum([oranges])/sum([Total Fruits])
end end end
Put this in worksheet & change the datatype to %. Now show your parameter. Now you will get % of each fruit type by total & when you change the values in parameter you can find the changes in your value.
If this is not your requirement, let me know.
Prashant's parameter extends what I set up, so you can filter on Fruit Types as well--I missed that part. Hopefully, you'll be able to get what you want from this.
Thank you for your reply! Your percentages are correct, and I managed to achieve my goal.
Thank you for your reply Prashant!
I tried to follow your steps but unfortunately didn't manage to build a view (stacked bar). Do you know how to make it possible? Please find attached the file with the results.
Fruit example (1).twbx 8.4 KB
I was previously suggested to parameter as you want to filter the dimensions. But now what I have concluded that you want a single stack bar with % contribution of each. So, Created one according to that. Let me know if this is not what you wanted.
Fruit example (1).twbx 10.3 KB
Yes, this is exactly what I wanted. Thank you very much Prashant!
Could you please add one more time an example workbook?
I am downloading it and it has no data source.
I am facing the same need and this example could help. Thank you!