Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
chris05
Frequent Visitor

Date Slicer

Hi,

I wanted to create a slicer similar to the below picture. My problem is it wont work as expected, for example, whenever I click MTD, Y and T wont show in the table display, its filtering based on the column values. and same for the other values.

My goal is if I click MTD it will show the data for month to date inluding today and Yesterday. same goes for YTD etc...

SelectedPeriod =
SWITCH(
SELECTEDVALUE(SlicerOptions[Period]),
"T", TODAY(),
"Y", TODAY() - 1,
"MTD", IF('Calendar'[Date] >= DATE(YEAR(TODAY()), MONTH(TODAY()), 1) && 'Calendar'[Date] <= TODAY(), 1, 0),
"LM", IF('Calendar'[Date] >= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1) && 'Calendar'[Date] <= EOMONTH(TODAY() - 1, 0), 1, 0)
)

chris05_0-1728934103530.png

 






1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @chris05 

Your idea is fantastic, but I would suggest checking the following:

 

1.Firstly, you need to ensure that you are using a measure rather than a calculated column or calculated table, as these cannot capture the values from slicers.

vlinyulumsft_0-1728958218158.png

2.Secondly, here is my sample data:

vlinyulumsft_1-1728958218159.png

3.I have modified your measure as follows:

SelectedPeriod =
VAR cc =
    SWITCH (
        SELECTEDVALUE ( SlicerOptions[Period] ),
        "T", IF ( MAX ( 'Calendar'[Date] ) = TODAY (), 1 ),
        "Y",
            IF ( MAX ( 'Calendar'[Date] ) = TODAY () - 1, 1 ),
        "MTD",
            IF (
                MAX ( 'Calendar'[Date] ) >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 )
                    && MAX ( 'Calendar'[Date] ) <= TODAY (),
                1
            ),
        "LM",
            IF (
                MAX ( 'Calendar'[Date] )
                    >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
                    && MAX ( 'Calendar'[Date] )
                        <= EOMONTH ( TODAY () - 1, 0 ),
                1
            ),
        BLANK ()
    )
RETURN
    IF ( ISFILTERED ( 'SlicerOptions'[Period] ), cc, 1 )

4.Apply the measure to a visualization and modify filter settings:

vlinyulumsft_2-1728958276140.png

 

 

5.Below are my final results, which I hope meet your expectations:

vlinyulumsft_3-1728958276142.png

vlinyulumsft_4-1728958293824.png

vlinyulumsft_5-1728958316296.png

vlinyulumsft_6-1728958379792.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi, @chris05 

Your idea is fantastic, but I would suggest checking the following:

 

1.Firstly, you need to ensure that you are using a measure rather than a calculated column or calculated table, as these cannot capture the values from slicers.

vlinyulumsft_0-1728958218158.png

2.Secondly, here is my sample data:

vlinyulumsft_1-1728958218159.png

3.I have modified your measure as follows:

SelectedPeriod =
VAR cc =
    SWITCH (
        SELECTEDVALUE ( SlicerOptions[Period] ),
        "T", IF ( MAX ( 'Calendar'[Date] ) = TODAY (), 1 ),
        "Y",
            IF ( MAX ( 'Calendar'[Date] ) = TODAY () - 1, 1 ),
        "MTD",
            IF (
                MAX ( 'Calendar'[Date] ) >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 )
                    && MAX ( 'Calendar'[Date] ) <= TODAY (),
                1
            ),
        "LM",
            IF (
                MAX ( 'Calendar'[Date] )
                    >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
                    && MAX ( 'Calendar'[Date] )
                        <= EOMONTH ( TODAY () - 1, 0 ),
                1
            ),
        BLANK ()
    )
RETURN
    IF ( ISFILTERED ( 'SlicerOptions'[Period] ), cc, 1 )

4.Apply the measure to a visualization and modify filter settings:

vlinyulumsft_2-1728958276140.png

 

 

5.Below are my final results, which I hope meet your expectations:

vlinyulumsft_3-1728958276142.png

vlinyulumsft_4-1728958293824.png

vlinyulumsft_5-1728958316296.png

vlinyulumsft_6-1728958379792.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.