Dynamic Index Price Value PowerBI

Viewed 15

I have an issue that I believe its very simple to tackle but I cannot find the way.

First I needed to scale/index an stock price to 1.0 in order to make it comparable with other stocks with dynamic timeframe.

I've found the solution here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Scaling-time-series-data-based-on-starting-date-value/m-p/987708#M12214

My issue now is that I need that measure to return a percentage of gain or loss, for example, if the measure above returns 1.2, I need it to return 0.2 or 20%.

Scaled Value 2 = 
VAR oneDateVisible =
HASONEVALUE(
    Dates[Date]
)

VAR firstVisibleDate =
FIRSTDATE(
    ALLSELECTED(
        Dates[Date]
    )
)

VAR scaler = 
CALCULATE(
    SUM(
        NAVs[Valor mil Cuotapartes]),
        firstVisibleDate
)

VAR result =
DIVIDE(
    SUM(
        NAVs[Valor mil Cuotapartes]),
        scaler
)

RETURN
IF(oneDateVisible,result)
1 Answers

I made it, it was a simple math workaround.

Scaled Value % = 

VAR VALUE_EXISTS = 
HASONEVALUE(
    Dates[Date]
)

VAR FIRST_DATE = 
FIRSTDATE(
    ALLSELECTED(
        Dates[Date]
    )
)

VAR FIRST_VALUE = 
CALCULATE(
    SUM(
        NAVs[VCP]),
        FIRST_DATE
)

VAR RESULT = 
DIVIDE(
    SUM(
        NAVs[VCP]) - FIRST_VALUE,
        FIRST_VALUE)  

RETURN 
IF(
    VALUE_EXISTS,
    RESULT,
)

Related