Return and the past price calculation in power BI with no correlated dates

18 Views Asked by At

I have a table in power BI as follow:

|Date    |price   |firm    |portfolio|
|dd/mm/yy|numeric |text    |text     |
|dd/mm/yy|numeric |text    |text     |
|dd/mm/yy|numeric |text    |text     |

I want to show in a table the t-1 price and the variation of the today vs t-1 price and for this I thought in a measure that show the t-1 price and another that calculate the return. My issue is that the Date column has only Chile's working days, so tha date is not necesarily correlative (this implies e.g. that the function DATEADD doesn't work). Can you help me with a way to solve it?

1

There are 1 best solutions below

0
Sam Nseir On

Try something similar to:

T-1 Price = 
  var thisDate = MAX(YourTable[Date])
  var prevDateRow = 
    TOPN(1,
      FILTER(ALLSELECTED(YourTable), YourTable[Date] < thisDate),
      [Date], DESC
    )
  return CALCULATE( MAX(YourTable[price]), prevDateRow )