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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
bourne2000
Helper V
Helper V

Showing last three months in the bar graph based on selecting month on the slicer?

Hi

 

I am having below table

 

bourne2000_0-1636323151906.png

 

I wanted to create a bar graph with month on the x-axis and value on the y axis. I need to create a month name filter and whenever I select single month, it show the last three months on the bar graph

 

For example, If I select April, the bar grapjh shows Jan, Feb, March and April

 

I tried to replicate the other posts solution, but no success. Can anyone advise please?

 

Sample PBIX file attached here https://we.tl/t-kWAov94QkZ

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @bourne2000 ,

I updated your sample pbix file(see attachment), please check whether that is what you want.

1. Delete the relationship between Date and Sheet1

yingyinr_1-1636527665637.png

2. Create a measure as below to get the sum of value

Measure = 
VAR _selyear =
    SELECTEDVALUE ( 'Date'[Year] )
VAR _selmonth =
    SELECTEDVALUE ( 'Date'[Month No] )
RETURN
    CALCULATE (
        SUM ( 'Sheet1'[Value] ),
        FILTER (
            'Sheet1',
            'Sheet1'[Year] = _selyear
                && 'Sheet1'[Month] >= _selmonth - 3
                && 'Sheet1'[Month] <= _selmonth
        )
    )

yingyinr_0-1636527610781.png

Best Regards

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @bourne2000 ,

I updated your sample pbix file(see attachment), please check whether that is what you want.

1. Delete the relationship between Date and Sheet1

yingyinr_1-1636527665637.png

2. Create a measure as below to get the sum of value

Measure = 
VAR _selyear =
    SELECTEDVALUE ( 'Date'[Year] )
VAR _selmonth =
    SELECTEDVALUE ( 'Date'[Month No] )
RETURN
    CALCULATE (
        SUM ( 'Sheet1'[Value] ),
        FILTER (
            'Sheet1',
            'Sheet1'[Year] = _selyear
                && 'Sheet1'[Month] >= _selmonth - 3
                && 'Sheet1'[Month] <= _selmonth
        )
    )

yingyinr_0-1636527610781.png

Best Regards

Ashish_Mathur
Super User
Super User

Hi,

See if my solution here helps - Flex a Pivot Table to show data for x months ended a certain user defined month.

You may just import this workbook into PBI Desktop.  In PBI Desktop, just go to File > Import > Power Query, PowerPivot and PowerView.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
jdbuchanan71
Super User
Super User

@bourne2000 

Take a look at this article that discusses what you are trying to accomplish.

https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors