Forum Discussion

cheryl0316's avatar
cheryl0316
Helper II
1 year ago
Solved

Dynamic columns/measures in matrix

I’d really appreciate any help with this. I’ve created a sample dataset and would like to build a matrix as follows:       When the user selects 2024 and 2023:   "Last Week" group should...
  • danextian's avatar
    1 year ago

    Hi cheryl0316 

    Ensure that you have a separate date dimensions table. Creat the following measures

    Current Year = 
    VAR _Year = CALCULATE ( MAX ( Dates[Year] ), ALLSELECTED ( Dates ) )
    RETURN
        CALCULATE (
            SUM ( 'Table'[Revenue] ),
            KEEPFILTERS ( Dates[Year] = _Year )
        )
    
    Previous Year = 
    VAR _Year = CALCULATE ( MIN ( Dates[Year] ), ALLSELECTED ( Dates ) )
    RETURN
        CALCULATE (
            SUM ( 'Table'[Revenue] ),
            KEEPFILTERS ( Dates[Year] = _Year )
        )
    
    Difference = 
    [Current Year] -  [Previous Year]

    Create these calculation items

    Last Week = 
    CALCULATE(
        SELECTEDMEASURE(),
        FILTER(
            ALL('Table'[Week No]),
            'Table'[Week No] = 52
        )
    )
    --NOTE: no 53  in your sample data for 2023 and 2024
    
    Last Month = 
    CALCULATE(
        SELECTEDMEASURE(),
        FILTER(
            ALL ( 'Dates' ),
            Dates[Month Number] = 12
        )
    )
    
    Last Quarter = 
    CALCULATE(
        SELECTEDMEASURE(),
        FILTER(
            ALL(Dates),
            Dates[Quarter] = 4
        )
    )