Forum Discussion
PowerBI Percentage Difference between two selected dates in a filter
Hello,
EuroK4238 aarp mahjonggwrote:Hi,
I'm new to PowerBI and so far ChatGPT has been my best friend, but it seems it has exhausted its usefulness because we're going around in circles with the same proposed solutions.
what i am trying to make is a report with balance sheet and income statement data for several industry actors, for several quarters, and it's fine so far, but what i want to add now is a dynamic percentage change for these values, which picks only the most recent and the oldest selected dates in a filter.So far, using this code i get a difference of zero.
The code used to select the dates is:
RecentDate = MAX('Balance Unpivot'[DATE])AncientDate= MIN('Balance Unpivot'[DATE])
This works, it shows the correct dates in a card visual element.then, the code used to pick the values for only these dates is as follows:ValueAncientDate =CALCULATE(SELECTEDVALUE('Balance Unpivot'[Values]),FILTER('Balance Unpivot','Balance Unpivot'[DATE] = [AncientDate]))ValueRecentDate =CALCULATE(SELECTEDVALUE('Balance Unpivot'[Values]),FILTER('Balance Unpivot','Balance Unpivot'[DATE] = [RecentDate]))this is where we run into issues, because when i put these two measures into a matrix, both give me the same result, so calculating the difference between them always gives zero.My data (unpivoted) is structured as follows:Columns: Company, Date, ROW_ID, Attribute (total assets, liabilities, etc) and Values.Please help!
The issue with your current calculation lies in the use of SELECTEDVALUE. To correctly calculate the percentage change, use SUM to aggregate the values for the ancient and recent dates. Then, use DIVIDE to calculate the percentage change. Ensure that the Values column is numeric and that other filters don't interfere with the date-based calculations.