从小计和总计行中排除特定计算
Exclude specific calculation from subtotal and grand total lines
我有这个 table :
我想计算每一天和每个组 1and2 %
即
(Attribute1/Attribute2)*100
但我不想将 1and2 %
包括在组小计中,也不希望在总计中包括
我创建了一个新的 table :
Table3 = UNION(DISTINCT('Table'[Attributes]);{{"1and2 %"}})
我做了这个计算 1and2 %
:
Measure =
SUMX (
DISTINCT ( 'Table3'[Attributes] );
SWITCH (
'Table3'[Attributes];
"1and2 %"; DIVIDE (
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute1" );
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute2" );
0
) * 100;
VAR a = 'Table3'[Attributes]
RETURN
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = a )
)
)
这是我得到的结果:
我想从组小计和总计中排除 1and2 %
(以及将来包含 % 的每个属性)。
我是 PowerBI 的新手,对类似 Excel 的公式不是很熟悉。
谁能帮我解决这个问题?
此致
我认为如果您仅计算 1and2 %
部分(过滤器上下文中唯一的部分)并且在其他情况下进行正常求和,您就可以得到想要的结果。
Measure =
IF (
SELECTEDVALUE ( 'Table3'[Attributes] ) = "1and2 %";
DIVIDE (
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute1" );
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute2" );
0
) * 100;
SUM ( 'Table'[Value] )
)
对于小计和总计,SELECTEDVALUE
returns 空白,因此条件失败,您只得到总和。
PowerBI 论坛的某个人给了我这个解决方案,这正是我要找的:
使用现有的创建另一个测量:
Measure 2 =
VAR __Table =
ADDCOLUMNS(
SUMMARIZE(
'Table 3',
[Group],
[Attribute],
"__Measure",[Measure]
),
"__IncludeInTotals",SEARCH("%",[Attribute],,-1)
)
RETURN
IF(
HASONEVALUE('Table 3'[Attribute]),
[Measure],
SUMX(FILTER(__Table,[__IncludeInTotals] = -1),[__Measure])
)
我有这个 table :
我想计算每一天和每个组 1and2 %
即
(Attribute1/Attribute2)*100
但我不想将 1and2 %
包括在组小计中,也不希望在总计中包括
我创建了一个新的 table :
Table3 = UNION(DISTINCT('Table'[Attributes]);{{"1and2 %"}})
我做了这个计算 1and2 %
:
Measure =
SUMX (
DISTINCT ( 'Table3'[Attributes] );
SWITCH (
'Table3'[Attributes];
"1and2 %"; DIVIDE (
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute1" );
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute2" );
0
) * 100;
VAR a = 'Table3'[Attributes]
RETURN
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = a )
)
)
这是我得到的结果:
我想从组小计和总计中排除 1and2 %
(以及将来包含 % 的每个属性)。
我是 PowerBI 的新手,对类似 Excel 的公式不是很熟悉。 谁能帮我解决这个问题?
此致
我认为如果您仅计算 1and2 %
部分(过滤器上下文中唯一的部分)并且在其他情况下进行正常求和,您就可以得到想要的结果。
Measure =
IF (
SELECTEDVALUE ( 'Table3'[Attributes] ) = "1and2 %";
DIVIDE (
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute1" );
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute2" );
0
) * 100;
SUM ( 'Table'[Value] )
)
对于小计和总计,SELECTEDVALUE
returns 空白,因此条件失败,您只得到总和。
PowerBI 论坛的某个人给了我这个解决方案,这正是我要找的:
使用现有的创建另一个测量:
Measure 2 =
VAR __Table =
ADDCOLUMNS(
SUMMARIZE(
'Table 3',
[Group],
[Attribute],
"__Measure",[Measure]
),
"__IncludeInTotals",SEARCH("%",[Attribute],,-1)
)
RETURN
IF(
HASONEVALUE('Table 3'[Attribute]),
[Measure],
SUMX(FILTER(__Table,[__IncludeInTotals] = -1),[__Measure])
)