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
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

 

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.

Top Solution Authors