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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
WishAskedSooner
Responsive Resident
Responsive Resident

Update Chart Filter Dynamically Based on Slicer Selection

Hi Experts!

 

I am investigating data lags in the Adventure Works PBIX. Accordingly, I have made some updates to the Sales table by trimming the data for each category as follows:

 

Accessories: No data past November 2019

Bikes: No data past May 2020

Clothing: No data past June 2020

Components: No data past February 2020

 

Requirement:

The user wants to view a single year plot of Sales performance by Category with the most up-to-date YTD Sales Amount versus Prior Year YTD Sales Amount.

 

Partial Solution:

I have created the following two measures that work as expected:

 

Sales_YTD =
    VAR _LatestOrderDateKey = MAX('Sales'[OrderDateKey])
    RETURN
        CALCULATE(SUM('Sales'[Sales Amount]), DATESYTD(CALCULATETABLE(VALUES('Date'[Date]), 'Date'[DateKey] <= _LatestOrderDateKey)))
 
Sales_PY_YTD = CALCULATE(SUM('Sales'[Sales Amount]), SAMEPERIODLASTYEAR(DATESYTD('Date'[Date])))
 
These are added to a plot along with a slicer on Category. Lastly, I added a Calculated Column to the Date table:
 
[Year] = YEAR('Date'[Date])
 
and used this as a filter in the plot which I hard coded to 2020. See below.
WishAskedSooner_0-1728307381276.png

 

Problem:

When the user clicks on Accessories, since the data is only through November 2019, the Year filter in the plot needs to be updated to 2019. Below is what the plot should update to if I hard code the filter value to 2019.

WishAskedSooner_1-1728308089316.png

How do I make the filter value update automatically to 2019 when the user selects Accessories versus Bikes, etc?

 

Thanks in advance for the help!

1 ACCEPTED SOLUTION

@dharmendars007 Thank you so much for your reply!

 

I tried your solution with some slight modifications:

 

I created the following three measures:

 

LatestOrderDateKey = MAX(Sales[OrderDateKey])
LatestOrderDateYear = MAXX(FILTER('Date', [DateKey] = [LatestOrderDateKey]), [Year])
Filter_YTD = IF(VALUES('Date'[Year]) = [LatestOrderDateYear], 1, 0)
 
So far, the first two measures work perfectly since they are filter-context sensitive. The LatestOrderDateYear updates to 2019 versus 2020 properly when put in a card. See below.
 
Next, I replaced the Year filter with the Filter_YTD measure in the Plot filters and set the value to is 1. However, the plot is not working as expected.
WishAskedSooner_0-1728313802510.png

I feel like I am so close and just need a little nudge in the right direction. Thank you so much for your help!

View solution in original post

2 REPLIES 2
dharmendars007
Super User
Super User

Hello @WishAskedSooner , 

 

You can use the below measure to get the MAX year and the use this measure to in a measure Dynamic Year and add this in the visual filter

 

MaxYearByCategory =
CALCULATE(MAX(Sales[OrderDateKey]),
Sales[Category] = SELECTEDVALUE(Sales[Category]))

 

DynamicYear = YEAR([MaxYearByCategory])

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

@dharmendars007 Thank you so much for your reply!

 

I tried your solution with some slight modifications:

 

I created the following three measures:

 

LatestOrderDateKey = MAX(Sales[OrderDateKey])
LatestOrderDateYear = MAXX(FILTER('Date', [DateKey] = [LatestOrderDateKey]), [Year])
Filter_YTD = IF(VALUES('Date'[Year]) = [LatestOrderDateYear], 1, 0)
 
So far, the first two measures work perfectly since they are filter-context sensitive. The LatestOrderDateYear updates to 2019 versus 2020 properly when put in a card. See below.
 
Next, I replaced the Year filter with the Filter_YTD measure in the Plot filters and set the value to is 1. However, the plot is not working as expected.
WishAskedSooner_0-1728313802510.png

I feel like I am so close and just need a little nudge in the right direction. Thank you so much for your help!

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.