Forum Discussion

Pikachu-Power's avatar
Pikachu-Power
Impactful Individual
5 years ago
Solved

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 ...
  • v-alq-msft's avatar
    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.