Forum Discussion
Matrix with Year/Month and LastYear/OneMonth
- 5 years ago
Hi, Pikachu-Power
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
YM(a calculated table):
YM = DISTINCT('Table'[YearMonth])There is no relationship betweent two table. You may create a measure as below.
Result = var x = MAX('YM'[YearMonth]) var y = VALUE(LEFT(x,4)) var m = VALUE(RIGHT(x,2)) return IF( MAX('Table'[YearMonth])<=x, IF( MAX('Table'[Year])=y, IF( MAX('Table'[Month])<=m, 1,0 ), IF( MAX('Table'[Month])=m, 1,0 ) ), 0 )Then you need to put the measure in the visual level filter and use 'YearMonth' column from 'YM' table to filter the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Let's assume we have a table with sample data
Table = ADDCOLUMNS(CALENDAR("2018-01-01","2021-12-31"),"Value",RANDBETWEEN(0,10),"MonthNum",MONTH([Date]),"Month",format([Date],"MMM"),"Year",YEAR([Date]))
Next step is to create disconnected tables that feed the Month and Year slicer
MSlicer = SUMMARIZE('Table','Table'[Month],'Table'[MonthNum])
YSlicer = VALUES('Table'[Year])
These slicers need to be made Single select.
next, add a measure.
Include := switch(true(),min('Table'[Year])=SELECTEDVALUE(YSlicer[Year]) && min('Table'[MonthNum])<SELECTEDVALUE(MSlicer[MonthNum]),1,
min('Table'[MonthNum])=SELECTEDVALUE(MSlicer[MonthNum]),1,0)
Then create your matrix visual, and add the measure to the visual filters, setting the filter to Include = 1
The result is as you expect. However you have a problem with the sorting of the years - I leave it up to you to decide how to do that.
- Pikachu-Power5 years agoImpactful Individual
Interesting solution, thanks. But the sorting will be really a problem. Is it possible to sort like in my picure? I also cant sort the month for the current year like in your case... the matrix only sorts for values.
And something like 2020 01, 2020 02 would make the table too wide.