Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Expand Matrix table all level in hierarchy - Always Visible while changing Column using Parameter

Hi,

I am using parameter/Slicer to change first column header from Quarter to Year values, I also added second and third header columns after time period column by turning off +- and stepped layout on row headers .

I noticed when I expand selection to the last level of hirarchy on Quarter period selection and then if I change this to Year selection, it automatically collapse column to first column and hide other two column header. I always have to click on top expand all level down to hierarchy to expand.

It's very confusing for viewers as they always have to click on expand hierachy button on top of matrix.

I published online after expanding on quareter, but when viewers change this to year it automatically collapse. I don't want to use bookmarks and switch axis in this case. Is there any other way, we can make all columns visible always rather than collapsing.

1 ACCEPTED SOLUTION
MarkLaf
Memorable Member
Memorable Member

This can be achieved but you need to construct a helper table that puts all your years and quarters into a single column and then performs a calculate depending on type (quarter vs. year). This allows a filter to just operate on a single field, which won't reset matrix visuals (unlike a parameter, which is switching out fields, thus altering the matrix structure and causing a reset).

help_2024-05-31_1.gif

Here are steps I took to achieve the above.

 

Table

DatePersonSalesCampaign
1/1/2024Matt10Winter
1/15/2024Matt15Winter
1/20/2024Amy15Winter
2/3/2024Amy5Winter
2/25/2024Matt20Winter
2/26/2024Amy10Winter
7/1/2024Matt10Summer
7/15/2024Matt5Summer
7/20/2024Amy20Summer
8/1/2024Amy10Summer
8/25/2024Amy5Summer
1/1/2023Matt10Winter
1/15/2023Matt10Winter
1/20/2023Amy10Winter
2/3/2023Amy5Winter
2/25/2023Amy20Winter
2/26/2023Matt10Winter
7/1/2023Matt5Summer
7/15/2023Amy10Summer
7/20/2023Amy15Summer
8/1/2023Amy15Summer
8/25/2023Amy5Summer

 

Dates (mark as date table)

 

Dates = 
GENERATE(
    CALENDAR( DATE( YEAR( MIN( 'Table'[Date] ) ), 1, 1 ), DATE( YEAR( MAX( 'Table'[Date] ) ), 12, 31 ) ),
    VAR _dt = [Date] RETURN
    ROW(
        "Year", YEAR( _dt ),
        "YearTxt", FORMAT( _dt, "YYYY" ),
        "QuarterNum", QUARTER( _dt ),
        "Quarter", "Q" & QUARTER( _dt )
    )
)

 

Output:

MarkLaf_2-1717178327555.png

 

DateHierarchySelect (helper table)

 

DateHierarchySelect = 
VAR _yrs = 
    GENERATE( 
        //using selectcolumns so column name is Period instead of YearTxt
        SELECTCOLUMNS( DISTINCT( Dates[YearTxt] ), "Period", Dates[YearTxt] ) , 
        ROW( "Period Scale", "Year" ) 
    )
VAR _qts = 
    GENERATE( 
        DISTINCT( Dates[Quarter] ), 
        ROW( "Period Scale", "Quarter" ) 
    )
RETURN
UNION( _yrs, _qts )

 

Output:

MarkLaf_1-1717178126202.png

 

Relationships

MarkLaf_3-1717178445524.png

 

Create a measure that iterates through DateHierarchySelect[Period Scale] and provides the scale-specific calc. In this instance we are just adding Sales. You may need a different iterator and different calculation depending on your objectives, but I think this provides the gist.

 

Sales_DynamicPeriod = 
SUMX( 
    VALUES( DateHierarchySelect[Period Scale] ), 
    SWITCH( 
        DateHierarchySelect[Period Scale], 
        "Year", 
            CALCULATE( 
                SUM( 'Table'[Sales] ), 
                TREATAS( VALUES( DateHierarchySelect[Period] ), Dates[YearTxt] ) 
            ),
        "Quarter", 
            CALCULATE( 
                SUM( 'Table'[Sales] ), 
                TREATAS( VALUES( DateHierarchySelect[Period] ), Dates[Quarter] ) 
            )
    )
)

 

Now, put together your slicer on DateHierarchySelect[Period Scale] and matrix with all levels expanded.

MarkLaf_6-1717179645741.png

 

MarkLaf_5-1717179553737.png

 

 

View solution in original post

5 REPLIES 5
MarkLaf
Memorable Member
Memorable Member

This can be achieved but you need to construct a helper table that puts all your years and quarters into a single column and then performs a calculate depending on type (quarter vs. year). This allows a filter to just operate on a single field, which won't reset matrix visuals (unlike a parameter, which is switching out fields, thus altering the matrix structure and causing a reset).

help_2024-05-31_1.gif

Here are steps I took to achieve the above.

 

Table

DatePersonSalesCampaign
1/1/2024Matt10Winter
1/15/2024Matt15Winter
1/20/2024Amy15Winter
2/3/2024Amy5Winter
2/25/2024Matt20Winter
2/26/2024Amy10Winter
7/1/2024Matt10Summer
7/15/2024Matt5Summer
7/20/2024Amy20Summer
8/1/2024Amy10Summer
8/25/2024Amy5Summer
1/1/2023Matt10Winter
1/15/2023Matt10Winter
1/20/2023Amy10Winter
2/3/2023Amy5Winter
2/25/2023Amy20Winter
2/26/2023Matt10Winter
7/1/2023Matt5Summer
7/15/2023Amy10Summer
7/20/2023Amy15Summer
8/1/2023Amy15Summer
8/25/2023Amy5Summer

 

Dates (mark as date table)

 

Dates = 
GENERATE(
    CALENDAR( DATE( YEAR( MIN( 'Table'[Date] ) ), 1, 1 ), DATE( YEAR( MAX( 'Table'[Date] ) ), 12, 31 ) ),
    VAR _dt = [Date] RETURN
    ROW(
        "Year", YEAR( _dt ),
        "YearTxt", FORMAT( _dt, "YYYY" ),
        "QuarterNum", QUARTER( _dt ),
        "Quarter", "Q" & QUARTER( _dt )
    )
)

 

Output:

MarkLaf_2-1717178327555.png

 

DateHierarchySelect (helper table)

 

DateHierarchySelect = 
VAR _yrs = 
    GENERATE( 
        //using selectcolumns so column name is Period instead of YearTxt
        SELECTCOLUMNS( DISTINCT( Dates[YearTxt] ), "Period", Dates[YearTxt] ) , 
        ROW( "Period Scale", "Year" ) 
    )
VAR _qts = 
    GENERATE( 
        DISTINCT( Dates[Quarter] ), 
        ROW( "Period Scale", "Quarter" ) 
    )
RETURN
UNION( _yrs, _qts )

 

Output:

MarkLaf_1-1717178126202.png

 

Relationships

MarkLaf_3-1717178445524.png

 

Create a measure that iterates through DateHierarchySelect[Period Scale] and provides the scale-specific calc. In this instance we are just adding Sales. You may need a different iterator and different calculation depending on your objectives, but I think this provides the gist.

 

Sales_DynamicPeriod = 
SUMX( 
    VALUES( DateHierarchySelect[Period Scale] ), 
    SWITCH( 
        DateHierarchySelect[Period Scale], 
        "Year", 
            CALCULATE( 
                SUM( 'Table'[Sales] ), 
                TREATAS( VALUES( DateHierarchySelect[Period] ), Dates[YearTxt] ) 
            ),
        "Quarter", 
            CALCULATE( 
                SUM( 'Table'[Sales] ), 
                TREATAS( VALUES( DateHierarchySelect[Period] ), Dates[Quarter] ) 
            )
    )
)

 

Now, put together your slicer on DateHierarchySelect[Period Scale] and matrix with all levels expanded.

MarkLaf_6-1717179645741.png

 

MarkLaf_5-1717179553737.png

 

 

Anonymous
Not applicable

@Anonymous  Thank you very much for your reply. I think that's the main challenge of default Matrix visual added in power BI, Its limited to some functionalities.
In the matrix, if we put a field with a hierarchy structure, it will not be expanded by default at the beginning, and dashboard users have to click on the drill-down button in the upper right corner to expand hierarchy each time. We can add toggle +- sign on the side otherwise user will get confuse, if they dont see +- on side and every time view willl collapse to default view.
I already searched other additional table / matrix visual, all of them ask for license to buy. For now I will add +- sign on the side and leave this on users to click on drill down level after changing the view each time.


Anonymous
Not applicable

@Anonymous Thank you for your reply, I already turn stepped layout off. I want to show all level of hierarchy into a matrix by default but my issue is it won't expand all levels by default.

Anonymous
Not applicable

Hi, @Anonymous 

Thank you very much for your reply. In the matrix, if you put a field with a hierarchy structure, it will not be expanded by default at the beginning, and you will need to click the drill-down button in the upper right corner to expand your hierarchy.
If the default matrix doesn't meet your needs, you can look for visuals in the visual marketplace that fit your situation.

vjianpengmsft_0-1716878072701.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hi, @Anonymous 

I think you can try turning off the stepped layout of the matrix:

vjianpengmsft_0-1716515559584.png

vjianpengmsft_1-1716515605363.png

For more details about the matrix, you can click on the link below:

Create a matrix visual in Power BI - Power BI | Microsoft Learn

vjianpengmsft_2-1716515677452.png

If you put a hierarchy into a matrix, it won't expand all levels by default, you need to click on 

vjianpengmsft_3-1716515764750.pngbutton to expand.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.