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.
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?
ID | Name | Date | Value | difference vs date-1 | % vs date-1 |
1 | A | Wednesday, July 1, 2020 | 10 | 10 | 0% |
1 | A | Thursday, July 2, 2020 | 20 | 10 | 100% |
1 | A | Friday, July 3, 2020 | 100 | 80 | 400% |
2 | B | Wednesday, July 1, 2020 | 10 | 10 | 0% |
2 | B | Thursday, July 2, 2020 | 1 | -9 | -90% |
2 | B | Friday, July 3, 2020 | 7 | 6 | 600% |
Solved! Go to 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:
For details,pls see attached.
@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
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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 |
ID | Name | Date | Value | difference vs date-1 | % vs date-1 |
1 | A | Wednesday, July 1, 2020 | 10 | 10 | 0% |
1 | A | Thursday, July 2, 2020 | 20 | 10 | 100% |
1 | A | Friday, July 3, 2020 | 100 | 80 | 400% |
2 | B | Wednesday, July 1, 2020 | 10 | 10 | 0% |
2 | B | Thursday, July 2, 2020 | 1 | -9 | -90 |
2 | B | Friday, July 3, 2020 | 7 | 6 | 600% |
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:
For details,pls see attached.
@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
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
104 | |
104 | |
87 | |
73 | |
66 |
User | Count |
---|---|
119 | |
111 | |
95 | |
79 | |
72 |