Performing SUM based on Group in Tableau

Today while working on one of my assignments I got a requirement to perform a SUM of one column values based on a Group of columns in Tableau and being a novice to Tableau I started searching on the internet to find a way to achieve it and after spending few hours I found a solution so thought of sharing over here how I did it.

Below is my data set and I want to calculate the Amount spent each Month and the Total Amount spent in all months, the Average spent, and the Percentage of the Amount spent on each category.

As a first step, I created a Calculated field and named it as AmountSpentPerMonth, and used a FIXED level of Detail Expressions with the following expression:

{FIXED [Name],[Month]:SUM([Amount])}

Next, I created another Calculated field and named it as TotalSpentForAllMonths, and used a FIXED level of Detail Expressions with the following expression:

{FIXED [Name]:SUM([AmountSpentPerMonth])}

Then I created another Calculated field and named it as AverageSpent, and used a FIXED level of Detail Expressions with the following expression:

SUM([TotalSpentForAllMonths])/TOTAL(COUNTD([Month]))

Then I created another Calculated field and named it as PercentageSpentOnEachCategory, and used a FIXED level of Detail Expressions with the following expression:

[Amount]

Moved all calculated fields on Sheet together with other data fields and changed Percentage Compute Using “Category” as shown in a screenshot below:

Advertisement

One thought on “Performing SUM based on Group in Tableau

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s