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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
TaraCrane
Regular Visitor

Filter 3 months based on slicer selection

Hello all,

 

I have a matrix based on a datasource and I need to show 3 months based on a slicer selection. I have 2 slicers, one showing years and one showing month names. The requriement is that when the user selects the year and month the matrix shows data for the selected month and the 2 months after that. The matrix shows full months, so from the first to the last of the 3rd month.

 

So if a user select 2023 and February then the matrtix needs to show all data from 1st Feb 2023 to 30 April 2023.

 

I tried implementing some of the suggested solutions from here but i just can't make it work, not sure how to limit any of these to my requirements:

https://radacad.com/power-bi-from-and-to-date-filtering-with-one-slicer

https://community.powerbi.com/t5/Desktop/Display-Data-for-Last-3-months-based-on-slicer-selection/m-...

 

Any help is greatly appreciated!

1 ACCEPTED SOLUTION

This did help in a way. There was a comment pointing to another video which helped me do this. Essentially my approach was to use Tabular Editor to create the filter which is applied to any measure, which was my preference.

The video covers that in the second half as the first half is about explaining the formula and which fields to use in the visual and slicers:

https://www.youtube.com/watch?v=d8Rm7dwM6gc&ab_channel=SQLBI

You need to create a Date table and then duplicate that. My final formula is this:

 

VAR NumofMonths = 3
 VAR ReferenceDate = MIN('Date Table 1'[Date])
 VAR SecondaryDate = 
    DATESINPERIOD(
        'Date Table 2'[Date],
        ReferenceDate,
        NumofMonths,
        MONTH
    )
VAR Result = 
    CALCULATE(
        SELECTEDMEASURE(),
        REMOVEFILTERS('Date Table 1'),
        KEEPFILTERS(SecondaryDate),
        USERELATIONSHIP('Date Table 1'[Date],'Date Table 2'[Date])
    )
 RETURN
    Result

 

As i was looking at a slicer to show me dates in the future i used MIN for my ReferenceDate. If looking for dates in the past then use MAX I think.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

This is exactly what I need and it helps a lot! Thank you!

@TaraCrane May I check if is possible not doing this through Tabular Editor? If yes, may I know how? Thank you.

Padycosmos
Solution Sage
Solution Sage

This did help in a way. There was a comment pointing to another video which helped me do this. Essentially my approach was to use Tabular Editor to create the filter which is applied to any measure, which was my preference.

The video covers that in the second half as the first half is about explaining the formula and which fields to use in the visual and slicers:

https://www.youtube.com/watch?v=d8Rm7dwM6gc&ab_channel=SQLBI

You need to create a Date table and then duplicate that. My final formula is this:

 

VAR NumofMonths = 3
 VAR ReferenceDate = MIN('Date Table 1'[Date])
 VAR SecondaryDate = 
    DATESINPERIOD(
        'Date Table 2'[Date],
        ReferenceDate,
        NumofMonths,
        MONTH
    )
VAR Result = 
    CALCULATE(
        SELECTEDMEASURE(),
        REMOVEFILTERS('Date Table 1'),
        KEEPFILTERS(SecondaryDate),
        USERELATIONSHIP('Date Table 1'[Date],'Date Table 2'[Date])
    )
 RETURN
    Result

 

As i was looking at a slicer to show me dates in the future i used MIN for my ReferenceDate. If looking for dates in the past then use MAX I think.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors