[英]Power Bi: how to parameterize Top N visual level filter
Since PowerBI
don't support Top N
filter on page level
, I want to use N as a parameter to change it at once per multiple visuals.由于
PowerBI
不支持page level
的Top N
个过滤器,因此我想使用 N 作为参数来为多个视觉对象一次更改它。 Is it possible?可能吗?
PSIn this video (9:15) solution for more complex case is provided. PS在此视频 (9:15)中提供了更复杂情况的解决方案。
In the end of this article sample file available在本文末尾提供示例文件
Using the sample dataset, insert a new parameter.使用示例数据集,插入一个新参数。
Add a measure as follows:如下添加度量:
Measure =
IF(
SELECTEDVALUE('Product'[Product Name]) IN
SELECTCOLUMNS(
TOPN(
[Parameter Value],
ADDCOLUMNS( ALL( 'Product'),"@Sales", [Sales Amount] ),
[@Sales]
),
"x",
'Product'[Product Name]),
1)
Every visual you want affected by the TopN should have this filter.您希望受 TopN 影响的每个视觉对象都应具有此过滤器。
That's it.而已。
From usability perspective it's preferable to return Sales Rank in measure.从可用性的角度来看,最好返回衡量的销售排名。
Solution below is a copy/paste from SQLBI experts solution with minimal code changes ( ALLSELECTED ( 'Product'[Product Name]
) replaced by ALLSELECTED ( 'Product' )
):下面的解决方案是来自SQLBI 专家解决方案的复制/粘贴,代码更改最少(
ALLSELECTED ( 'Product'[Product Name]
) 替换为ALLSELECTED ( 'Product' )
):
rnkSales =
IF (
ISINSCOPE ( 'Product'[Product Name] ),
VAR ProductsToRank = [TopN Value]
VAR SalesAmount = [Sales Amount]
RETURN
IF (
SalesAmount > 0,
VAR VisibleProducts =
CALCULATETABLE (
VALUES ( 'Product' ),
ALLSELECTED ( 'Product') //ALLSELECTED ( 'Product'[Product Name] )
)
VAR Ranking =
RANKX (
VisibleProducts,
[Sales Amount],
SalesAmount
)
RETURN
IF (
Ranking > 0 && Ranking <= ProductsToRank,
Ranking
)
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.