Forum Discussion

Delphia's avatar
Delphia
Icon for Advocate II rankAdvocate II
4 years ago
Solved

date slicers influence each other problem

Dear community, I need your help with date slicers.   In my report I should have two types of date slicers: predefined periods (overall, last week, last month, etc.) and date range (to choose a...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Delphia 

    Power BI doesn't support you to set default range in slicer. You can set default range in your visual.

    Here I build a sample to show you how to create visuals be imapcted by two slicers.

    My Sample data is from 2021/08/01 to 2021/10/05.

    I build two unrelated tables Date and Period to create slicers by Dax.

    Date = 
    CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])) 
    Period = {"Last Week","Overall","This Month"}

    Then create a measure as below.

    Filter =
    VAR _LogicPeriod =
        SWITCH (
            SELECTEDVALUE ( Period[Value] ),
            "Overall", 1,
            "Last Week",
                IF ( SUM ( 'Table'[Weeknum] ) = WEEKNUM ( TODAY () ) - 1, 1, 0 ),
            "This Month", IF ( SUM ( 'Table'[Month] ) = MONTH ( TODAY () ), 1, 0 ),
            0
        )
    VAR _DateRangeStart =
        MIN ( 'Date'[Date] )
    VAR _DateRangeEnd =
        MAX ( 'Date'[Date] )
    RETURN
        IF (
            ISFILTERED ( Period[Value] ),
            SWITCH (
                SELECTEDVALUE ( Period[Value] ),
                "Overall", 1,
                "Last Week",
                    IF ( SUM ( 'Table'[Weeknum] ) = WEEKNUM ( TODAY () ) - 1, 1, 0 ),
                "This Month", IF ( SUM ( 'Table'[Month] ) = MONTH ( TODAY () ), 1, 0 ),
                0
            ),
            IF (
                ISFILTERED ( 'Date'[Date] ),
                IF (
                    MAX ( 'Table'[Date] ) >= _DateRangeStart
                        && MAX ( 'Table'[Date] ) < _DateRangeEnd,
                    1,
                    0
                ),
                IF ( SUM ( 'Table'[Month] ) = MONTH ( TODAY () ), 1, 0 )
            )
        )

    Create a visual ,add this measure into Filter Field in this visual and set it to show items when value =1.

    Result is as below. 

    By Default visual will show values in this month. 

    Period slicer has higher level than Date slicer. Select Last week:

    Select Overall:

    If Period slicer is not selected, then we can filter the visual by range in Date slicer.

    Best Regards,
    Rico Zhou

     

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