Reputation: 60756
I'm trying to wrap my head around how to created a calculated field in Tableau that is calculated after the source data is pivoted. My source data is "long" i.e. normalized and looks like this:
+---------+---------+-------+
| Company | Measure | Value |
+---------+---------+-------+
| A | Sales | 100 |
+---------+---------+-------+
| A | Exp | -10 |
+---------+---------+-------+
| B | Sales | 200 |
+---------+---------+-------+
| B | Exp | -30 |
+---------+---------+-------+
(Actually every company would have more than two records, but this is simplified)
What I'd like to get out is the following where Net
is calculated as Sales + (2 * Exp)
.
+---------+---------+-------+-------+
| Company | Sales | Exp | Net |
+---------+---------+-------+-------+
| A | 100 | -10 | 80 |
+---------+---------+-------+-------+
| B | 200 | -30 | 140 |
+---------+---------+-------+-------+
I can get the following by simply having Company
as my row and Measure
as my column and then sum(Value)
:
+---------+---------+-------+
| Company | Sales | Exp |
+---------+---------+-------+
| A | 100 | -10 |
+---------+---------+-------+
| B | 200 | -30 |
+---------+---------+-------+
But how do I calculate an additional column based on the result of pivoting Measure
?
Upvotes: 1
Views: 841
Reputation: 3348
Does this get you what you need?
The crux is creating calculated fields for Exp
and Sales
like this:
Exp =
if [Measure] = "Exp" then [Value] end
Sales =
if [Measure] = "Sales" then [Value] end
Those become measures you can use as the columns.
Upvotes: 2