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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
charles_g
Advocate I
Advocate I

Is it possible to ignore the year part of a MonthYear slicer and keep the filter on the month?

Hello,

 

My date table has Month, Year and MonthYear columns.

I use the MonthYear column in a slicer e.g. the user can select August 2021, September 2021...

In some visuals on the page, as well as in tooltips, I would like to show values for the selected month but in previous years.

 

Is there a way to ignore the year part of the slicer and keep the month part?

I know I could use 2 diferent slicers for the year and the month, but I find this solution less elegant.

 

Thanks for any help!

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

If you have a date parameter table that you use for your slicer that is not related to other tables, you could write measures that read in the selected slicer value and apply whatever filtering you choose based on that selection. This isn't how date dimension tables are usually set up though (you usually want to have a relationship that filters your fact tables).

 

Your measure might look something like this:

DateSlicedMeasure =
VAR SelectedDate = SELECTEDVALUE ( DateSlicer[MonthYear] )
RETURN
    CALCULATE ( [Measure], DateTable[Month] = MONTH ( SelectedDate ) )

 

View solution in original post

5 REPLIES 5
AlexisOlson
Super User
Super User

If you have a date parameter table that you use for your slicer that is not related to other tables, you could write measures that read in the selected slicer value and apply whatever filtering you choose based on that selection. This isn't how date dimension tables are usually set up though (you usually want to have a relationship that filters your fact tables).

 

Your measure might look something like this:

DateSlicedMeasure =
VAR SelectedDate = SELECTEDVALUE ( DateSlicer[MonthYear] )
RETURN
    CALCULATE ( [Measure], DateTable[Month] = MONTH ( SelectedDate ) )

 

Thank you, that worked!

Here are the steps I took based on your suggestion :

 

1. Create a new table to use in the slicer

MonthNumber and relativeMonthIndex are used for sorting

 

MonthYearSlicer = 
SUMMARIZE(
'Calendar',
'Calendar'[MonthYear],
'Calendar'[Year],
'Calendar'[Month],
'Calendar'[MonthNumber],
'Calendar'[relativeMonthIndex]

)

 

2. Create a calculation group with the following calculated items to transfer the filter I want from MonthYearSlicer to my Calendar table. (with a calculation group I don't need to rewrite all my measures)

 

keepMonth =
CALCULATE (
SELECTEDMEASURE (),
TREATAS (
VALUES(MontYearSlicer[Month]),
Calendar[Month]
)
)

keepMonthYear=
CALCULATE (
SELECTEDMEASURE (),
TREATAS (
VALUES(MonthYearSlicer[MonthYear],
Calendar[MonthYear]
)
)

 

3. Replace Calendar[MonthYear] by MonthYearSlicer[MonthYear] in the slicer

 

4. Add the new calculation group in the filter pane for each visual.

 

5. Select keepMonth for the visuals where I want to display other years, keepMonthYear for the other visuals

Looks good! Thanks for detailing the steps for future readers.

charles_g
Advocate I
Advocate I

Thanks for your reply.

That works to get the value I want in a measure but it will not let me display a bar graph showing 2020 and 2021 for the selected month.

The measure will show the value for 2020 in 2021. The slicer still prevents other years from showing.

PaulDBrown
Community Champion
Community Champion

Just create measures to return the desired value. Along the lines of:

Previous year = CALCULATE (Your measure], DATEADD(Date[Date], -1, YEAR])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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