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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
MoeData
Advocate II
Advocate II

How to have dynamic date filter on Columns (NOT rows) in matrix visual

I would like to make a matrix visual which is filled with a single measure. On the page I have a slicer for years. For the matrix, on rows I have a list of items and on columns I want to have the selected year and its previous year. 
matrix.png
I cannot find a way to do this. I have made a flag measure so be able to have only the selected year and the year before that, but when I use the flag as a filter for the matrix, the matrix still shows all the years in the data model. 

I can think of 3 other ways to get some matrix, but none of them are really useful and what I want.
The methods I already tried:

1) Defining two separate measures, one for the selected year and one for the previous year. But I really want to use only a single measure.

2) Having rows and columns swapped. That works (Apparently Power BI treats rows and columns differently and their difference is more than just being horizontal and vertical in the matrix visual). But since I have a very long list of items, I get a really long matrix in horizontal direction which does not look good and is not really useful for the user either. 
3) Having an extra table visual where its contents are filtered by the slicer I already have in the page (so it shows the selected year and the year before that). Then I can click on the contents of the extra table and see the desired outcome in the matrix. This is not an elegant solution and needs a 2-step filtering by the user, which needs to be done in an specific order. Also if the user clicks on somewhere in the page then selection on the extra table disappears and user has to click on the contents of the table again. 


So what I try to build is the shown matrix, with only a single measure, if anyone has an idea how to achieve that.

Thanks! 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@MoeData , if you do not want 2 measures , then you need an independent date/year table  

 

then you can get two year data like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Year])
var _min = _max -1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Year] >=_min && 'Date'[Year] <=_max))

 

You can use year from date table in column

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

@MoeData , As long they are coming from independent date table you can try like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = Eomonth(_max, -3* [select N Value] )+1 // 
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@MoeData , if you do not want 2 measures , then you need an independent date/year table  

 

then you can get two year data like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Year])
var _min = _max -1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Year] >=_min && 'Date'[Year] <=_max))

 

You can use year from date table in column

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak 
Thanks! That is actually nice, but I wished I haven't oversimplified the question then. 
In reality I have two slicers: One for the year and one for the quarter. 
And instead of showing the current and previous year, I actually want to see the current quarter and its previous N quarters. (If N can be defined as a variable so it can be easily modified, it will be really great!)

Do you have a DAX suggestion for this modified and more difficult situation?

Thanks!

@MoeData , As long they are coming from independent date table you can try like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = Eomonth(_max, -3* [select N Value] )+1 // 
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak 
Nice! 
How about defining "var _max" as var _max = max(Date1[Date]) ? Any drawbacks?
I had to remove sum() in the last line of your DAX to make it work. 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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