Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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)
)
Solved! Go to Solution.
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.
2.Secondly, here is my sample data:
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:
5.Below are my final results, which I hope meet your expectations:
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.
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.
2.Secondly, here is my sample data:
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:
5.Below are my final results, which I hope meet your expectations:
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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
76 | |
75 | |
54 | |
38 | |
31 |
User | Count |
---|---|
99 | |
56 | |
50 | |
42 | |
40 |