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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Pikachu-Power
Post Prodigy
Post Prodigy

Matrix with Year/Month and LastYear/OneMonth

hello all,

 

i am looking for a matrix like:

 

Unbenannt.PNG 

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
v-alq-msft
Community Support
Community Support

Hi, @Pikachu-Power 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

d2.png

 

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.

d3.png

 

Best Regards

Allan

 

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

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @Pikachu-Power 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

d2.png

 

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.

d3.png

 

Best Regards

Allan

 

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

lbendlin
Super User
Super User

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]))
 
lbendlin_0-1613165541836.png

 

lbendlin
Super User
Super User

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.

 

lbendlin_0-1613133607612.png

 

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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