Forum Discussion
tomekm
Helper III
1 year agoValue difference for max and min years
Hello,
I would need to determine the price difference for each ID, between their min year and max year, and then divide that amount by the number of year occurances for that specific ID. Here's how the data looks like. The last column is the desired output:
For ID=A, 33.45 - 36 = -2.55, divided by 3 = -0.85.
| ID | Year attribute | Price | Price Diff %: Min Year-Max Year/number of Years per ID |
| A | Y1 | 33.45 | -0.85 |
| A | Y2 | 45.51 | -0.85 |
| A | Y3 | 36 | -0.85 |
| B | Y1 | 22.3 | 1.15 |
| B | Y2 | 20 | 1.15 |
| C | Y1 | 55 | -5.5 |
| C | Y2 | 52 | -5.5 |
| C | Y3 | 77 | -5.5 |
| C | Y4 | 65 | -5.5 |
| C | Y5 | 32 | -5.5 |
| C | Y6 | 88 | -5.5 |
Thank you.
Hello tomekm
Please try this Measure
Price Diff =VAR MinPrice =CALCULATE(MINX(FILTER('Table', 'Table'[Year attribute] = MIN('Table'[Year attribute])),'Table'[Price]),ALLEXCEPT('Table', 'Table'[ID]))VAR MaxPrice =CALCULATE(MAXX(FILTER('Table', 'Table'[Year attribute] = MAX('Table'[Year attribute])),'Table'[Price]),ALLEXCEPT('Table', 'Table'[ID]))VAR YearCount = CALCULATE(COUNT('Table'[Year attribute]), ALLEXCEPT('Table', 'Table'[ID]))VAR PriceDiff = MinPrice - MaxPriceRETURNDIVIDE(PriceDiff, YearCount, 0)Thanks,
Pankaj Namekar | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
3 Replies
- pankajnamekar25
Super User
Hello tomekm
Please try this Measure
Price Diff =VAR MinPrice =CALCULATE(MINX(FILTER('Table', 'Table'[Year attribute] = MIN('Table'[Year attribute])),'Table'[Price]),ALLEXCEPT('Table', 'Table'[ID]))VAR MaxPrice =CALCULATE(MAXX(FILTER('Table', 'Table'[Year attribute] = MAX('Table'[Year attribute])),'Table'[Price]),ALLEXCEPT('Table', 'Table'[ID]))VAR YearCount = CALCULATE(COUNT('Table'[Year attribute]), ALLEXCEPT('Table', 'Table'[ID]))VAR PriceDiff = MinPrice - MaxPriceRETURNDIVIDE(PriceDiff, YearCount, 0)Thanks,
Pankaj Namekar | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
- tomekm
Helper III
Thank you!
- Ashish_Mathur
Super User
Hi,
Here is a calculated column formula solution
Column = divide(LOOKUPVALUE(Data[Price],Data[Year attribute],CALCULATE(min(Data[Year attribute]),FILTER(Data,Data[ID]=EARLIER(Data[ID]))),Data[ID],Data[ID])-LOOKUPVALUE(Data[Price],Data[Year attribute],CALCULATE(MAX(Data[Year attribute]),FILTER(Data,Data[ID]=EARLIER(Data[ID]))),Data[ID],Data[ID]),CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID]))))Hope this helps.