cancel
Showing results for
Search instead for
Did you mean:  Post Prodigy

## Matrix with Year/Month and LastYear/OneMonth

hello all,

i am looking for a matrix like: If i choose for example the first 9 month and the year 2020 i want to see (beside choosen year and 9 month) the last two years with the last choosen month. in two matrices it is no problem. but it is possible to show that in one matrix? in the rows i have hierchies with +/-. would be easier to control that in one matrix.

thanks for ideas.

1 ACCEPTED SOLUTION  Community Support

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.

4 REPLIES 4  Community Support

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.  Super User III

If you noticed I added a MonthNum column. You can sort the Month column by that.

You can use the same approach to sort the years differently.

Table = ADDCOLUMNS(CALENDAR("2018-01-01","2021-12-31"),"Value",RANDBETWEEN(0,10),"MonthNum",MONTH([Date]),"Month",format([Date],"MMM"),"Year",YEAR([Date]),"YearSort",2050-YEAR([Date]))   Super User III

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.   Post Prodigy

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.  ## Helpful resources

Announcements #### Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group! #### Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks #### Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp! Top Solution Authors
Top Kudoed Authors
Users online (3,896)