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
siva54
Helper I
Helper I

Last 5 months datat from a selected month filter.

Hi Team,

 

I need to a graph like, if we selected a month then we need to show the last 5 months in graph.(Seen in below)

example:- if we select year =2022 and Month = february then in graph we need to show  oct 2021, Nov 2021, Dec 2021, Jan 2022 and Feb 2022.

 

siva54_0-1650517764069.png

 

The data we have is 

DateValues
January 01 202112
February 01 202133
March 01 202137
April 01 202164
May 01 20213
June 01 202188
July 01 202175
August 01 202131
September 01 20219
October 01 20218
November 01 202144
December 01 202118
January 01 202275
February 01 202244
March 01 202222
April 01 202268
May 01 202292
June 01 202237
July 01 202269
August 01 202290
September 01 20227
October 01 202260
November 01 202221
December 01 202212

 

Thanks in Advance

 

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @siva54 ,

According to your description, here's my solution.

1.Create a new date table,

Date =
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "MMMM" ),
    "MonthNum", MONTH ( [Date] )
)

2.Create a measure,

Check =
IF (
    MAX ( 'Table'[Date] )
        > EOMONTH (
            DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[MonthNum] ), 1 ),
            -5
        )
        && MAX ( 'Table'[Date] )
            <= EOMONTH (
                DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[MonthNum] ), 1 ),
                0
            ),
    1,
    0
)

Put the new date table in the slicer, put the check measure in the visual filter and make its value to 1, get the correct result. 

vkalyjmsft_0-1651047762730.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @siva54 ,

According to your description, here's my solution.

1.Create a new date table,

Date =
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "MMMM" ),
    "MonthNum", MONTH ( [Date] )
)

2.Create a measure,

Check =
IF (
    MAX ( 'Table'[Date] )
        > EOMONTH (
            DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[MonthNum] ), 1 ),
            -5
        )
        && MAX ( 'Table'[Date] )
            <= EOMONTH (
                DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[MonthNum] ), 1 ),
                0
            ),
    1,
    0
)

Put the new date table in the slicer, put the check measure in the visual filter and make its value to 1, get the correct result. 

vkalyjmsft_0-1651047762730.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

amitchandak
Super User
Super User

@siva54 , if you select one date/month and need more, you need slicer on independent date table

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = eomonth(_max, -5) +1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

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.