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

Calucate % difference of date & date -1

I've a table like this, and want to get 1) difference vs date-1; 2)% vs date-1

 

Below somehow can caluate difference between 2 selected date, but what if i want date-1?

2 Day difference % =
var _max = MAXX('transformed', 'transformed'[Date])
var _min = MINX('transformed', 'transformed'[Date])
var newdate = calculate(sum('transformed'[Value]),filter(ALL('transformed'[Date]),[Date]=_max))
var olddate = calculate(sum('transformed'[Value]),filter(ALL('transformed'[Date]),[Date]=_min))

return
if(olddate = 0, 0, ROUND((newdate-olddate)/olddate*100, 0))

 

IDNameDateValuedifference vs date-1% vs date-1
1AWednesday, July 1, 202010100%
1AThursday, July 2, 20202010100%
1AFriday, July 3, 202010080400%
2BWednesday, July 1, 202010100%
2BThursday, July 2, 20201-9-90%
2BFriday, July 3, 202076600%
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Create 2 calculated columns as below:

difference vs date-1 = 
var _previousvalue=CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[Date]=EARLIER('Table'[Date])-1))
Return
'Table'[Value]-_previousvalue
% vs date-1 = 
var _previousvalue=CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[Date]=EARLIER('Table'[Date])-1))
Return
IF(_previousvalue=BLANK(),0,DIVIDE('Table'[difference vs date-1],_previousvalue))

And you will see:

Annotation 2020-07-20 105406.png

For details,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@Anonymous 

It seems you want to calculate the VALUE and % difference from the previous day. But, I am not sure you still want to do it within each ID, please explain:
How did you calculate 10, -10, and - in the last three lines?

If you are satisfied with my answer, please mark it as a solution so others can easily find it.

Don't forget to give KUDOS  to replies that help answer your questions


Subscribe to ExcelFort: Learn Power BI, Power Query and Excel
 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Thanks for pointing it out.

apologize for the copy & paste mistake. I updated to below.

Take B as example:

-9

= 1-10

-1000%
=(1-10)/10*100

 

IDNameDateValuedifference vs date-1% vs date-1
1AWednesday, July 1, 202010100%
1AThursday, July 2, 20202010100%
1AFriday, July 3, 202010080400%
2BWednesday, July 1, 202010100%
2BThursday, July 2, 20201-9-90
2BFriday, July 3, 202076600%

Hi @Anonymous ,

 

Create 2 calculated columns as below:

difference vs date-1 = 
var _previousvalue=CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[Date]=EARLIER('Table'[Date])-1))
Return
'Table'[Value]-_previousvalue
% vs date-1 = 
var _previousvalue=CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[Date]=EARLIER('Table'[Date])-1))
Return
IF(_previousvalue=BLANK(),0,DIVIDE('Table'[difference vs date-1],_previousvalue))

And you will see:

Annotation 2020-07-20 105406.png

For details,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

@Anonymous


Please check the attached file, it answers your question: https://1drv.ms/u/s!AmoScH5srsIYgYF-iRdl6MKD76W4WA?e=ASxIyx

 

If you are satisfied with my answer, please mark it as a solution so others can easily find it.

Don't forget to give KUDOS  to replies that help answer your questions


Subscribe to ExcelFort: Learn Power BI, Power Query and Excel

 

 

 




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

AllisonKennedy
Super User
Super User

Try something similar to what you have done, but instead of _max and _min use a FILTER on ALL date table to filter for date < SELECTEDVALUE date to get _prev date.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.