Forum Discussion

gomezc73's avatar
gomezc73
Helper V
3 years ago
Solved

Create a comparative Matrix with data by year filtered with two slicers

Hi,     I am having trouble trying to create a matrix with the data filtered by two slicers (to compare the data by year).     In other words, my data have a monthly summary of sales by product/y...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi gomezc73 ,

     

    I suggest you to inactive all relationships betwen two dimyear tables and your data table.

    Data model:

    Measure:

    Measure = 
    VAR _RecentYear =
        SELECTEDVALUE ( 'Year'[Year 1] )
    VAR _PreviousYear =
        SELECTEDVALUE ( 'Year 2'[Year 2] )
    VAR _Amount =
        CALCULATE (
            SUM ( 'Table'[Amount] ),
            FILTER ( 'Table', 'Table'[Year] IN { _PreviousYear, _RecentYear } )
        )
    VAR _Part1 =
        CALCULATE (
            SUM ( 'Table'[Amount] ),
            FILTER ( ALLEXCEPT ( 'Table', 'Table'[Month] ), 'Table'[Year] = _RecentYear )
        )
    VAR _Part2 =
        CALCULATE (
            SUM ( 'Table'[Amount] ),
            FILTER ( ALLEXCEPT ( 'Table', 'Table'[Month] ), 'Table'[Year] = _PreviousYear )
        )
    RETURN
        IF ( HASONEVALUE ( 'Table'[Year] ), _Amount, _Part2 - _Part1 )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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