4

I have a table that looks like:

id     aff1    aff2    aff3    value
1       a        x      b        5
2       b        c      x        4
3       a        b      g        1

I would like to aggregate the aff columns to calculate the sum of "value" for each aff. For example, the above gives:

aff    sum
a       6
b       10
c       4
g       1
x       9

Ideally, I'd like to do this directly in tableau without remaking the table by unfolding it along all the aff columns.

Alex R.
  • 1,397
  • 3
  • 18
  • 33

1 Answers1

3

You can use Tableau’s inbuilt pivot method as below, without reshaping in source .

  1. CTRL Select all 3 dimensions you want to merge , and click on pivot .

enter image description here

  1. You will get your new reshaped data as below, delete other columns :

enter image description here

  1. Finally build your view.

enter image description here

I hope this answers . Rest other options for the above results include JOIN at DB level, or creating multiple calculated fields for each attribute value which are not scalable.

minatverma
  • 1,090
  • 13
  • 24
  • 1
    Doesn't Tableau only allow pivoting on Excel data sources...? (At least as of Desktop 10.4.) Any solution for all data sources, such as query results? – Ward W Mar 15 '18 at 00:04
  • As of version 2018.1 unpivot can still be done only with excel and csv data sources. If you do not want to get out of Tableau to achieve this, you may use a **Custom SQL** using SQL keyword UNPIVOT in it. https://learn.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-2017 – Hakan ERDOGAN May 22 '18 at 14:54