Forum Discussion

damit23183's avatar
damit23183
Icon for Microsoft Employee rankMicrosoft Employee
5 years ago
Solved

Caculate Last N Month by using Slicer

Hi,   I am trying to calculate count by using slicer which means when i select monthyear and put number in parameter slicer than i should get value in bar chart. For Example, Slicer is created bas...
  • v-yingjl's avatar
    5 years ago

    Hi damit23183 ,

    I have created a simliar sample file in the below that you can check, hopes it could help you in some ways.

    Create a new year-month column both in date table and acutal table:

    YearMonth = YEAR([Date])*100+MONTH([Date])

    Create a measure like this, put it in the visual filter and set its value as 1:

    Measure =
    VAR tab =
        TOPN (
            SELECTEDVALUE ( Parameter[Parameter] ),
            CALCULATETABLE (
                DISTINCT ( 'Table'[YearMonth] ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[YearMonth] <= SELECTEDVALUE ( 'Date'[YearMonth] )
                )
            ),
            [YearMonth]
        )
    RETURN
        IF ( SELECTEDVALUE ( 'Table'[YearMonth] ) IN tab, 1, 0 )
    

     

    Best Regards,
    Yingjie Li

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