0
votes

Consider the following table. I'm trying to take the sum of the columns value1, and value2 according to their respective column names. I.e the summation for A should result in 3+6 = 9, and the summation for B should result in 5+4=10.

column1 value1 column2 value2
  A     3       B       4
  B     5       A       6 

I have created a calculated field that takes the sum of both columns as seen below

SUM([value1]) + SUM([value2])

Ultimately, I'm trying display a bar chart, where one bar shows the total value for A, and the other bar shows the total value for B. I have placed column1 in rows, and the result of the calculated field in columns. I initially expected for tableau to sum up the values according to the field name. However it simply looks at the name in column1, and sums up value1 and value2 horizontally. In retrospect, it now makes sense why it's doing this. However I've looked through the docs extensively, and could not find a feasible solution to this. Hoping for some extra guidance!

Many thanks.

1

1 Answers

0
votes

Declared within the sum your desired result.

sum(if col1 = 'A' then val1 end) + sum(if col2 = 'A' then val2 end)