Power Bi:如何参数化Top N视觉级别过滤器[重复]

问题描述 投票:0回答:2

由于

PowerBI
不支持
Top N
page level
进行过滤, 我想使用 N 作为参数来针对多个视觉效果立即更改它。 可以吗?

P.S.在此视频(9:15)提供了更复杂情况的解决方案。

本文末尾提供示例文件

powerbi dax data-analysis powerbi-desktop measure
2个回答
2
投票

使用示例数据集,插入新参数。

添加如下措施:

Measure = 
IF(
    SELECTEDVALUE('Product'[Product Name]) IN 
    SELECTCOLUMNS( 
        TOPN(
            [Parameter Value], 
            ADDCOLUMNS( ALLSELECTED( 'Product'),"@Sales", [Sales Amount] ), 
            [@Sales]
            ), 
        "x", 
        'Product'[Product Name]), 
1)

您希望受 TopN 影响的每个视觉效果都应该有此过滤器。

就是这样。


0
投票

从可用性角度来看,最好返回衡量的销售排名。

下面的解决方案是来自 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
                    )
            )
    )

© www.soinside.com 2019 - 2024. All rights reserved.