Forum Discussion

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

Displaying previous value instead of blank

I have 3 tables: Products Product quantity by date Calendar On my report I have a date slicer from calendar where I can select a single date. Then I have a table visual that displays ALL produc...
  • v-jingzhang's avatar
    5 years ago

    Hi JKoivu 

     

    You can use a measure to get the result.

    Previous quantity = 
    VAR __previousDate =
        CALCULATE (
            MAX ( 'Quantity by date'[Date] ),
            FILTER (
                ALL ( 'Quantity by date' ),
                'Quantity by date'[Date] < MAX ( 'Calendar'[Date] )
                    && 'Quantity by date'[Product ID] = MAX ( 'Products'[Id] )
            )
        )
    RETURN
        CALCULATE (
            SUM ( 'Quantity by date'[Quantity] ),
            FILTER (
                ALL ( 'Quantity by date' ),
                'Quantity by date'[Date] = __previousDate
                    && 'Quantity by date'[Product ID] = SELECTEDVALUE ( 'Products'[Id] )
            )
        )

     

    If you calculate previous quantity in a calculated column, you should also use a measure to get the corresponding previous quantity column value when you hope to use a slicer to switch it.

     

    Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as the solution to help other members find it.