Forum Discussion

Joerg's avatar
Joerg
Icon for Helper I rankHelper I
5 years ago
Solved

Measure to calculate zero values

Dear All I have 2 tables, a table with periods and the other with values and dates.   The relation between both are columns "YYYY-MM" and "YearMonth".   When I put in a matrix column "...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Joerg ,

    I updated my sample pbix file(see attachment), please check whether that is what you want.

    1. Create another yearmonth dimension table(Don't create any relationship with another tables) and apply the yearmonth field as slicer

    Yearmonth = VALUES('Period'[YYYY-MM])

    2. Create two measures as below to get the sum of values

    TempsValue = 
    VAR _selym =
        SELECTEDVALUE ( 'Yearmonth'[YYYY-MM] )
    VAR _selyyyymm =
        SELECTEDVALUE ( 'Period'[YYYY-MM] )
    VAR _ymvalue =
        VALUE ( CONCATENATE ( LEFT ( _selym, 4 ), RIGHT ( _selym, 2 ) ) )
    VAR _svalue =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[YearMonth] = SELECTEDVALUE ( 'Period'[YYYY-MM] )
                    && VALUE (
                        CONCATENATE ( LEFT ( 'Table'[YearMonth], 4 ), RIGHT ( 'Table'[YearMonth], 2 ) )
                    ) <= _ymvalue
            )
        )
    RETURN
        IF ( _selyyyymm <= _selym, _svalue + 0, BLANK () )
    Sum of value = SUMX(VALUES('Period'[YYYY-MM]),[TempsValue])

    3. Create matrix visual (Columns: YYYY-MM(from the table with period info)  Values:[Sum of value])

    Best Regards