Forum Discussion

Jidapa18's avatar
Jidapa18
Frequent Visitor
8 months ago
Solved

Remove blank rows from matrix but still contain data

I stuck in the matrix visual to remove blank rows in the matrix. I have the data that contain in 9 levels show as picture below, I create the matrix as picture below. I try to create t...
  • danextian's avatar
    8 months ago

    Hi Jidapa18 

    Assuming that's how you hierarchy is - once an upper level hierarchy is already blank the rest are expected to be blank - create a column that counts the number of nonblank levels or  turn this into a measure.

    NonBlank Levels = 
    COUNTROWS (
        FILTER (
            {
                State[Level1],
                State[Level2],
                State[Level3],
                State[Level4],
                State[Level5],
                State[Level6],
                State[Level7],
                State[Level8],
                State[Level9]
            },
            NOT ( ISBLANK ( [Value] ) )
        )
    )
    

    You also need to enable subtotals. You can't make the values appear in the upper levels if subtotal is not enabled.

    Create a measure that will check whether the current hierarchy number matches the max number of hierarchy levels.

    RemoveBlankRows 2 = 
    VAR VisibleLevel =
        SWITCH (
            TRUE (),
            ISINSCOPE ( 'State'[Level9] ), 9,
            ISINSCOPE ( 'State'[Level8] ), 8,
            ISINSCOPE ( 'State'[Level7] ), 7,
            ISINSCOPE ( 'State'[Level6] ), 6,
            ISINSCOPE ( 'State'[Level5] ), 5,
            ISINSCOPE ( 'State'[Level4] ), 4,
            ISINSCOPE ( 'State'[Level3] ), 3,
            ISINSCOPE ( 'State'[Level2] ), 2,
            ISINSCOPE ( 'State'[Level1] ), 1
        )
    VAR _nonBlankLevels =
        SELECTEDVALUE ( State[NonBlank Levels] )
    RETURN
        IF ( VisibleLevel = _nonBlankLevels, MAX ( State[ID] ) )
    

    Note: If the goal is to display only the deepest non-blank level in a hierarchy while hiding all upper levels, that isn’t possible. To reach any lower level in a hierarchy, the upper levels must first be present and expanded.