Forum Discussion

KM007's avatar
KM007
Icon for Helper II rankHelper II
8 years ago
Solved

Calculating Price change and % Growth

Hi   I have a table with 596 Fund Names and contains prices(Value).   I wish to add 3 x columns: Price change % change YTD % change Many thanks
  • Greg_Deckler's avatar
    Greg_Deckler
    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.