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
Anonymous
Not applicable

Creating a dynamic measure to calculate percent difference over range of values from slicer

I am trying to calculate the % change over a slected range of dates from a 'Between' slicer. For example: If I selected the date range of 01-01-2010 to 02-02-2021 I would like to see the gross difference in value and peretnage change, by category. I have built measures to calculate this metric for 1 year and 6 months I just can't figure out how to do it dynamically, if its even possible at all. 

 

Here are examples of my 1-year difference measures: 

 

Latest_value_meas = LOOKUPVALUE('table'[value],'table'[Date_Col],[Latest_Date_Meas],'table'[Category],SELECTEDVALUE('table'[Category]))

 

1_Yr_ago = LOOKUPVALUE('table'[value],'table'[Date_Col],DATEADD(LASTDATE('table'[Date_col]),-1,YEAR),'table'[Category],SELECTEDVALUE('table'[Category]))
 
1_Yr_Gross_Diff = [Latest_value_meas]-[1_Yr_ago]
 
1_Yr_Perc_Diff = [1_Yr_Gross_Diff]/[1_Yr_ago]
 
Any thoughts on how to achieve this?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I believe I have found the solution, by plugging you var_min measure into my LOOKUPVALUE function I was able to retrieve the correct values. The final measures used were: 

var _min = minx(ALLSELECTED('Date'),'Date'[Date])

 

and

 

earlier_value = LOOKUPVALUE('table'[value],'table'[Date_Col],var_min,'table'[Category],SELECTEDVALUE('table'[Category]))

 

 

Thank you!

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Not very clear, Do you want diff between max and min date ?

 

example

measure =
var _max = maxx(ALLSELECTED('Date'),'Date'[Date])
var _min = minx(ALLSELECTED('Date'),'Date'[Date])
return
calculate(countrows(Table), filter('Date', 'Date'[Date] =_Max)) - calculate(countrows(Table), filter('Date', 'Date'[Date] =_Min))

 

or

One year behind measure with date tbale

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

or

 

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
Anonymous
Not applicable

I believe I have found the solution, by plugging you var_min measure into my LOOKUPVALUE function I was able to retrieve the correct values. The final measures used were: 

var _min = minx(ALLSELECTED('Date'),'Date'[Date])

 

and

 

earlier_value = LOOKUPVALUE('table'[value],'table'[Date_Col],var_min,'table'[Category],SELECTEDVALUE('table'[Category]))

 

 

Thank you!

 

Anonymous
Not applicable

Thank you for response, 

 

To clarify what I am attepmting to do: I would like to create measures that would use the dates selected in the slicer to calculate the difference in the value from the earlier date to the later date. I am wondering I can use the slicer to input the date values into a LOOKUPVALUE function to find the values for the selected date for each category? 

 

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