在tableau中计算部分占整体比重时,常常需要进行不同维度之间的聚合计算,fixed和exclude这两个函数在此场景中经常被用到。
两个函数定义如下:
fixed函数:
{fixed 维度1,维度2,… : 聚合度量},仅使用指定的维度(维度1,维度2,…)计算聚合度量;
exclude函数:
{exclude 维度1,维度2,… : 聚合度量},如果指定的维度(维度1,维度2,…)出现在试图中,则计算聚合时会排除这些维度分组的影响。
eg:对下述table表中的数据进行计算
table:
| month | first_class | second_class | num |
|---|---|---|---|
| 1月 | 财务 | 核算 | a |
| 1月 | 财务 | 税务 | b |
| 2月 | 财务 | 核算 | c |
| 2月 | 财务 | 税务 | d |
在表table的基础上创建4个计算字段,分别为:
t1={fixed month,first_class : sum(num)};
t2={fixed month,first_class,second_class : sum(num)};
t3={exclude month,first_class : sum(num)};
t4={exclude month,first_class,second_class : sum(num)};
4个字段创建完之后的表table为:
| month | first_class | second_class | num | t1 | t2 | t3 | t4 |
|---|---|---|---|---|---|---|---|
| 1月 | 财务 | 核算 | a | a+b | a | a+c | a+b+c+d |
| 1月 | 财务 | 税务 | b | a+b | b | b+d | a+b+c+d |
| 2月 | 财务 | 核算 | c | c+d | c | a+c | a+b+c+d |
| 2月 | 财务 | 税务 | d | c+d | d | b+d | a+b+c+d |
通过在表格中列出fixed和exclude组合不同维度的聚合值,可以比较清晰明了的知道fixed和exclude聚合函数的计算过程。
实例:在下述table1表的基础上创建上述计算字段t1,t2,t3,t4
table1:
| month | first_class | second_class | num |
|---|---|---|---|
| 1月 | 财务 | 核算 | 134 |
| 1月 | 财务 | 税务 | 231 |
| 2月 | 财务 | 核算 | 154 |
| 2月 | 财务 | 税务 | 264 |
在tableau上的计算结果如下图所示:

本文介绍在Tableau中使用fixed和exclude函数进行不同维度间的聚合计算方法,并通过具体示例展示这两种函数的应用。

3449

被折叠的 条评论
为什么被折叠?



