按维度聚合

时间:2016-03-16 17:43:01

标签: tableau

最近,数据库更新导致过去两个字段成为新表。因此,我们的库存跟踪系统已经不再像这样:

Item | Old Count | New Count | Difference
A    | 2         | 4         | 2
B    | 5         | 3         | -2
C    | 0         | 1         | 1

到此(在表连接之后):

Item | Action    | Quantity
A    | Current   | 2         
A    | Add       | 2         
B    | Current   | 5
B    | Remove    | 1
B    | Remove    | 1
C    | Current   | 0
C    | Add       | 3
C    | Remove    | 2

我希望能够创建计算字段,将所有这些新信息压缩回原始示例中的格式,但似乎无法弄清楚SQL之外的内容。

任何建议都将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:0)

这是我用四个计算字段做的。

创建旧计数:if [Action] = 'current' then [Quantity] end

创建保留:if [Action] = 'add' then [Quantity] elseif [Action] = 'remove' then -[Quantity] end

创建新计数:sum([hold])+sum([old count]) 创建差异:[new count]-sum([old count])

然后我将它们放在像样本一样的行和列上。请参阅随附的工作簿https://dl.dropboxusercontent.com/u/60455118/160316%20stack%20question.twbx