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

How to create a dynamic DAX measure value that changes according to the filter applied on the visual

Hi all!

I have this DAX measure in Power BI;

CALCULATE ( SUM(Table1[amount]) , YEAR(Table2[date]) = 2021 )

 

This measure is used in a visual that is being filtered by a _DateTable[date], that is joined to a date column in Table1. The visual filter is currently set to 2021, however when I change it to 2022 the values are incorrect as the measure still points to 2021 in Table2...

 

Is it possible to write this measure in a way that updates the Table2[date] value in the measure to the same value the _DateTable[date] is filtering for...

 

So something like;

CALCULATE ( SUM(Table1[amount]) , YEAR(Table2[date]) = YEAR(_DateTable[date]) )

 

I hope I make sense.

All suggestions will be much appreciated, Thank you!

1 ACCEPTED SOLUTION
Adescrit
Impactful Individual
Impactful Individual

Hi @HB13 

 

You could try:

 

Measure = 
VAR __SelectedYear = SELECTEDVALUE(DateTable[Year])
RETURN
CALCULATE ( SUM(Table1[amount]) , YEAR(Table2[date]) = __SelectedYear )

 

I'm assuming there is a column [Year] in the DateTable for this to work.


Did I answer your question? Mark my post as a solution!
My LinkedIn

View solution in original post

4 REPLIES 4
Adescrit
Impactful Individual
Impactful Individual

Hi @HB13 

 

You could try:

 

Measure = 
VAR __SelectedYear = SELECTEDVALUE(DateTable[Year])
RETURN
CALCULATE ( SUM(Table1[amount]) , YEAR(Table2[date]) = __SelectedYear )

 

I'm assuming there is a column [Year] in the DateTable for this to work.


Did I answer your question? Mark my post as a solution!
My LinkedIn

This worked beautifully! Thank you so so much!!

Adescrit
Impactful Individual
Impactful Individual

This may be over-complicating things though. If your Table1 is connected to DateTable via a date column in both, then your formula only needs to be the below. You can then create a YEAR column in your date table and use that to filter Table1.

CALCULATE ( SUM(Table1[amount]) )

 


Did I answer your question? Mark my post as a solution!
My LinkedIn
amitchandak
Super User
Super User

@HB13 , with help from a date/year table

 

//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

 

or

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

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