由于
PowerBI
不支持 Top N
对 page level
进行过滤,
我想使用 N 作为参数来针对多个视觉效果立即更改它。
可以吗?
P.S.在此视频(9:15)提供了更复杂情况的解决方案。
在本文末尾提供示例文件
从可用性角度来看,最好返回衡量的销售排名。
下面的解决方案是来自 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 =
FILTER( -- filters out data with no sales
CALCULATETABLE (
VALUES ( 'Product' ),
ALLSELECTED ( 'Product') -- Use this if VisualFilterTopN equivalent required
//ALLSELECTED ( 'Product'[Product Name] ) -- Original code - returns TopN per dimension
),
NOT ISBLANK( [Sales Amount] ) -- looks more universal then [Sales Amount]>0 (if calculation for Margin required, it could be negative)
)
VAR Ranking =
RANKX (
VisibleProducts,
[Sales Amount],
SalesAmount
)
RETURN
IF (
Ranking > 0 && Ranking <= ProductsToRank,
Ranking
)
)
)