Tableau:数据重新整形后的计算字段

时间:2015-09-28 18:35:26

标签: tableau

我正试图围绕如何在源数据被转动后计算的Tableau中创建计算字段。我的源数据是“长的”,即标准化,看起来像这样:

+---------+---------+-------+
| Company | Measure | Value |
+---------+---------+-------+
| A       | Sales   | 100   |
+---------+---------+-------+
| A       | Exp     | -10   |
+---------+---------+-------+
| B       | Sales   | 200   |
+---------+---------+-------+
| B       | Exp     | -30   |
+---------+---------+-------+

(实际上每家公司都会有两个以上的记录,但这是简化的)

我想知道的是Net计算为Sales + (2 * Exp)的情况。

+---------+---------+-------+-------+
| Company | Sales   | Exp   | Net   |
+---------+---------+-------+-------+
| A       | 100     | -10   | 80    |
+---------+---------+-------+-------+
| B       | 200     | -30   | 140   |
+---------+---------+-------+-------+

我只需将Company作为我的行,Measure作为我的列,然后sum(Value)即可获得以下内容:

+---------+---------+-------+
| Company | Sales   | Exp   | 
+---------+---------+-------+
| A       | 100     | -10   |
+---------+---------+-------+
| B       | 200     | -30   | 
+---------+---------+-------+

但是如何根据旋转Measure的结果计算其他列?

1 个答案:

答案 0 :(得分:2)

这能满足您的需求吗?

关键是为ExpSales创建计算字段,如下所示:

Exp = if [Measure] = "Exp" then [Value] end

Sales = if [Measure] = "Sales" then [Value] end

这些成为可以用作列的措施。 enter image description here