代码之家  ›  专栏  ›  技术社区  ›  whytheq

DAX中的嵌套列组

  •  1
  • whytheq  · 技术社区  · 6 年前

    我有两个数据表:

    1.事实:

    ImaginaryFact = 
    DATATABLE (
        "FruitKey", INTEGER,
        "Amount",   INTEGER,
        { 
            { 1, 1 }, 
            { 1, 5 }, 
            { 1, 2 }, 
            { 2, 2 },
            { 2, 3 },
            { 3, 4 },
            { 3, 5 },
            { 4, 2 },
            { 5, 2 },
            { 6, 3 },
            { 7, 8 }
        } )
    

    2.尺寸:

    Dimension = 
    DATATABLE (
        "FruitKey", INTEGER,
        "Fruit",    STRING,
        "Colour",   STRING,
        { 
            { 1, "Apple",   "Green" }, 
            { 6, "Apple",   "Blue" }, 
            { 7, "Apple",   "Red" },         
            { 2, "Pear",    "Pink" }, 
            { 3, "Orange",  "Green" }, 
            { 4, "Kiwi",    "Green" }, 
            { 5, "Mango",   "Green" }
        } )
    

    通过这个简单的连接:

    enter image description here

    然后我创建了这两个度量:

    Amount = SUM( ImaginaryFact[Amount] )
    
    Rank Fruity = 
    IF(
        ISFILTERED( 'Dimension'[Colour] ),
        RANKX( ALLSELECTED( 'Dimension'[Colour] ), [Amount] ),
        IF(
           ISFILTERED( 'Dimension'[Fruit] ),
            RANKX( ALLSELECTED( 'Dimension'[Fruit] ), [Amount] )
        )
    )
    

    如果我创建了一个“矩阵”,那么“等级水果”的度量意味着我可以在水果和颜色之间上下移动,等级仍然有效,它会将我想要的总行清空,因为该行没有被过滤:

    enter image description here

    enter image description here

    这就是问题所在 当我向下钻取层次结构时,我希望为分类汇总返回空白,与“总计”行为空一样…

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Frostytheswimmer    6 年前

    请尝试使用if(isfiltered(),)函数,而不是if(hasoneValue(),,)

    https://powerpivotpro.com/2013/03/isfiltered-a-better-way-to-detect-totals/