Forum Discussion

Tae's avatar
Tae
Frequent Visitor
6 years ago
Solved

Slicer to select current month as default

Hi,   I have created a dropdown date selection slicer so that my users can review the historical information. I want to set this slicer selection default to the current month, but it appears...
  • v-gizhi-msft's avatar
    6 years ago

    Hi,

     

    According to your description, I create a table to test:

    Please take following steps:

    1)create a calculated table:

    Slicer =

    UNION (

        VAR t =

            DISTINCT (

                ADDCOLUMNS (

                    SELECTCOLUMNS ( 'Table', "Month Year", FORMAT ( 'Table'[Date], "MMMM YYYY" ) ),

                    "minDate", CALCULATE (

                        MIN ( 'Table'[Date] ),

                        FILTER ( 'Table', [Month Year] = FORMAT ( 'Table'[Date], "MMMM YYYY" ) )

                    )

                )

            )

        RETURN

            SELECTCOLUMNS (

                ADDCOLUMNS ( t, "Rank", RANKX ( t, [minDate],, ASC, DENSE ) ),

                "Month Year", [Month Year],

                "Rank", [Rank]

            ),

        DATATABLE ( "Month Year", STRING, "Rank", INTEGER, { { "Last Month", 0 } } )

    )

    And it shows:

    2)create a measure:

    IsFiltered =

    IF (

        FORMAT ( SELECTEDVALUE ( 'Table'[Date] ), "MMMM YYYY" )

            IN FILTERS ( Slicer[Month Year] ),

        1,

        IF (

            "Last Month" IN FILTERS ( Slicer[Month Year] ),

            IF (

                SELECTEDVALUE ( 'Table'[Date] )

                    >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )

                    && SELECTEDVALUE ( 'Table'[Date] )

                        < DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ),

                1,

                -1

            ),

            -1

        )

    )

    3)choose table visual and set measure ‘IsFiltered’ as 1:

    4)choose column ‘Month Year’ of table ‘Slicer’ as a slicer:

    5)choose the ‘Last Month’ and the result shows:

    Here is my test pbix file:

    pbix 

     

    Best Regards,

    Giotto Zhi