In power BI, I am computing the percentage difference between Stock price index levels over the last year.
Ann pch =
VAR __EarliestValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
DATEADD(LASTDATE('Calendar'[Date]),-1,YEAR))
VAR __LastDateValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
LASTDATE('Calendar'[Date]))
RETURN
CALCULATE(
DIVIDE(__LastDateValue,__EarliestValue) -1)
The above is correct but there is a bug: some dates fall on the weekend, or other non-trading days, in which case I want to select the next nonblank value for __EarliestValue
and the previous nonblank value in the case of __LastDateValue
.
Could anyone suggest the code to implement this.
I am very much a DAX/Power BI novice. Thank you very much.
Data Sample: