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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

select the data of 6 recent months based on text date slicer

Hi, here is my data looks like:

捕获.PNG

filterYM is the slicer, I want to show 6 months based on selected filterYM, for example, when I select filterYM=202205, how can I get the data that dataYM start from 202112 and end with 202205, do you have any ideas? Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a YM dimension table

yingyinr_1-1662024132417.png

2. Create a measure as below:

Flag = 
VAR _selfym =
    SELECTEDVALUE ( 'FilterYM'[dataYM] )
VAR _selym =
    SELECTEDVALUE ( 'Table'[dataYM] )
VAR _year =
    VALUE ( LEFT ( _selfym, 4 ) )
VAR _month =
    VALUE ( RIGHT ( _selfym, 2 ) )
VAR _minym =
    IF (
        _month >= 6,
        VALUE (
            CONCATENATE ( _year, IF ( _month - 5 < 10, "0" & ( _month - 5 ), _month - 5 ) )
        ),
        VALUE (
            CONCATENATE (
                _year - 1,
                IF (
                    12 - ( 5 - _month ) < 10,
                    "0" & ( 12 - ( 5 - _month ) ),
                    12 - ( 5 - _month )
                )
            )
        )
    )
RETURN
    IF ( VALUE ( _selym ) >= _minym && VALUE ( _selym ) <= VALUE ( _selfym ), 1, 0 )

3. Create a visual with the filter condition(Flag is 1)

yingyinr_0-1662024010366.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @Anonymous ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a YM dimension table

yingyinr_1-1662024132417.png

2. Create a measure as below:

Flag = 
VAR _selfym =
    SELECTEDVALUE ( 'FilterYM'[dataYM] )
VAR _selym =
    SELECTEDVALUE ( 'Table'[dataYM] )
VAR _year =
    VALUE ( LEFT ( _selfym, 4 ) )
VAR _month =
    VALUE ( RIGHT ( _selfym, 2 ) )
VAR _minym =
    IF (
        _month >= 6,
        VALUE (
            CONCATENATE ( _year, IF ( _month - 5 < 10, "0" & ( _month - 5 ), _month - 5 ) )
        ),
        VALUE (
            CONCATENATE (
                _year - 1,
                IF (
                    12 - ( 5 - _month ) < 10,
                    "0" & ( 12 - ( 5 - _month ) ),
                    12 - ( 5 - _month )
                )
            )
        )
    )
RETURN
    IF ( VALUE ( _selym ) >= _minym && VALUE ( _selym ) <= VALUE ( _selfym ), 1, 0 )

3. Create a visual with the filter condition(Flag is 1)

yingyinr_0-1662024010366.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

amitchandak
Super User
Super User

@Anonymous , Create a table with distinct filterYM and dataYM , and then create rank on dataYM 

 

dataYM Rank = Rankx('Date',[dataYM],,asc, dense)

 

Use filterYM  in slicer from this new date table 

 

Then try a meausre 

 

measure =

Var _max = maxx(allselected('Date'), 'Date'[dataYM Rank])

return 

calculate(sum(Table[Value]), filter('Date', 'Date'[dataYM Rank] >= _max -6 && 'Date'[dataYM Rank] <=_max))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors