Forum Discussion

NSC7's avatar
NSC7
Helper I
2 years ago
Solved

How to do selective row total in Matrix

Hi All, I need help with matrix total. below is the table screenshot. ASP= Rev * Unit $= (ASP Current month - ASP Prev month) * Unit of current month   Total of $ should only total for current y...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi NSC7 ,

    Please try to create  measure with below dax formula:

    $ =
    VAR _a =
        SELECTEDVALUE ( 'Table'[Month-Year] )
    VAR _b =
        SELECTEDVALUE ( 'Table'[Product] )
    VAR _c =
        CALCULATE (
            [ASP],
            FILTER (
                ALL ( 'Table' ),
                [Product] = _b
                    && DATEDIFF ( [Month-Year], _a, MONTH ) = 1
            )
        )
    VAR _d =
        SELECTEDVALUE ( 'Table'[Unit] )
    VAR _e = [ASP]
    VAR cur_year =
        YEAR ( TODAY () )
    VAR _result =
        IF ( YEAR ( _a ) = cur_year, ( _e - _c ) * _d, BLANK () )
    RETURN
        _result
    
    ASP = SELECTEDVALUE('Table'[Rev])*SELECTEDVALUE('Table'[Unit]) 
    Measure = IF(ISINSCOPE('Table'[Month-Year]),[$],SUMX('Table',[$]))

    Add a matrix visual with fields and measure:

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.