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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Dynamic column headers in matrix based on date slicer selection

Hi ,

I have a slicer with Year, Quarter, Monthname , Week,Day and based on the slicer selection the column headers should changed. I am able to make this happen by creating a table with just these and unpivoting these columns. But the dates are not sorting. 

Thanks 

2 REPLIES 2
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a calculated column as header filed to meet your requirement:

 

ColumnHeader = 
var yearTable = ADDCOLUMNS(SELECTCOLUMNS (
        GROUPBY ( 'Table', 'Table'[Date].[Year], 'Table'[Date] ),
        "Header", [Year],
        "Date", [Date]
    ),"Name","Year")
    var quarterTable = ADDCOLUMNS(SELECTCOLUMNS (
        GROUPBY ( 'Table', 'Table'[Date].[Quarter], 'Table'[Date] ),
        "Header", [Quarter],
        "Date", [Date]
    ),"Name","Quarter")
    var monthTable =  ADDCOLUMNS(SELECTCOLUMNS (
        GROUPBY ( 'Table', 'Table'[Date].[MonthNo], 'Table'[Date] ),
        "Header", [MonthNo],
        "Date", [Date]
    ),"Name","Month")
    var dayTable = ADDCOLUMNS(SELECTCOLUMNS (
        GROUPBY ( 'Table', 'Table'[Date].[Day], 'Table'[Date] ),
        "Header", [Day],
        "Date", [Date]
    ),"Name","Day")
var weekTable = FILTER(CROSSJOIN(GENERATESERIES(1,53),DISTINCT('Table'[Date])),WEEKNUM([Date])=[Value])
return
UNION (
    ADDCOLUMNS(yearTable,"Sort",RANKX(yearTable,[Header],,ASC,Dense),"NameSort",5),
    ADDCOLUMNS(quarterTable,"Sort",RANKX(quarterTable,[Header],,ASC,Dense),"NameSort",4),
    SELECTCOLUMNS(ADDCOLUMNS(monthTable,"Sort",RANKX(monthTable,[Header],,ASC,Dense)),"Header",Format([Date],"MMMM"),"Date",[Date],"Name",[Name],"Sort",[Sort],"NameSort",3),
    ADDCOLUMNS(dayTable,"Sort",RANKX(dayTable,[Header],,ASC,Dense),"NameSort",1),
    SELECTCOLUMNS(weekTable,"Header","WK "&[Value],"Date",[Date],"Name","Week","Sort",[Value],"NameSort",2)
)

 

"Header" Column is sorted by "Sort" column and the "Name" column is sorted by the "NameSort" column

 

4.jpg5.jpg6.jpg

 


If it doesn't meet your requirement, Could you please show the exact expected result based on the tables that we have shared?


By the way, PBIX file as attached.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Community Champion
Community Champion

Are they actually dates or text? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

You may need to create some kind of numeric Sort By column and flag your column to sort by this other column. Tough to say though.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors