Forum Discussion
Calculating Price change and % Growth
- 8 years ago
OK, the formula is:
Previous Value = MAXX(FILTER(Funds,Funds[Index]=(EARLIER(Funds[Index])-1)),Funds[Value])
MAXX
The MAXX is just any table aggregation. We could also have used MINX or SUMX here because we only intend to return a single row. MAXX's formula generically is MAXX(Table,Expression). In this case, the results of our FILTER clause are out table and we are returning the MAX of the Value column from the single row returned by the FILTER clause.
FILTER
We are filtering the Funds table where a row's [Index] equals the CURRENT (EARLIER) value of the [Index] minus 1. So, what is going on here is that if a row has an Index of 7, EARLIER will take on that value, I added parenthesis around the EARLIER and -1 to make certain this is happening correctly. So, when we FILTER the table, we will return the row whose Index is 7-1 or 6.
So, what may be going on here is what I was afraid of originally, you Index field is not in order by Date. So, you will probably have to go back to:
Previous Value = VAR previousDate = MAXX( FILTER(Funds, Funds[Fund Name]=EARLIER(Funds[Fund Name]) && Funds[Date]<EARLIER(Funds[Date])),Funds[Date]) RETURN MAXX(FILTER(Funds,Funds[Fund Name]=EARLIER(Funds[Fund Name]) && Funds[Date] = previousDate),Funds[Value])
This *should* do the same thing but ensure that you are only dealing with the same fund and the order of the Index doesn't matter, it will always return the previous date's Value.
Hi Greg_Deckler
May I ask for your assistance further
Please see attached photo.
Column "Previous Value" is showing an incorrect value and I don't fully comprehend the formula to decipher where error is.
Thanks
OK, the formula is:
Previous Value = MAXX(FILTER(Funds,Funds[Index]=(EARLIER(Funds[Index])-1)),Funds[Value])
MAXX
The MAXX is just any table aggregation. We could also have used MINX or SUMX here because we only intend to return a single row. MAXX's formula generically is MAXX(Table,Expression). In this case, the results of our FILTER clause are out table and we are returning the MAX of the Value column from the single row returned by the FILTER clause.
FILTER
We are filtering the Funds table where a row's [Index] equals the CURRENT (EARLIER) value of the [Index] minus 1. So, what is going on here is that if a row has an Index of 7, EARLIER will take on that value, I added parenthesis around the EARLIER and -1 to make certain this is happening correctly. So, when we FILTER the table, we will return the row whose Index is 7-1 or 6.
So, what may be going on here is what I was afraid of originally, you Index field is not in order by Date. So, you will probably have to go back to:
Previous Value = VAR previousDate = MAXX( FILTER(Funds, Funds[Fund Name]=EARLIER(Funds[Fund Name]) && Funds[Date]<EARLIER(Funds[Date])),Funds[Date]) RETURN MAXX(FILTER(Funds,Funds[Fund Name]=EARLIER(Funds[Fund Name]) && Funds[Date] = previousDate),Funds[Value])
This *should* do the same thing but ensure that you are only dealing with the same fund and the order of the Index doesn't matter, it will always return the previous date's Value.
- KM0078 years ago
Helper II
That worked! Yay
Thank you
- v-huizhn-msft8 years ago
Microsoft Employee
Hi KM007,
As you have resolved your issue, please mark the right reply as answer, so more people like you can get solution easily and clearly. Thanks for inderstanding.
Best Regards,
Angelia - fleal8 years agoFrequent Visitor
this formula worked perfectly in my database, but the performance was pretty bad. Could someone help me get the same result using DAX (not calculated column)?