Forum Discussion

CharlesRondo's avatar
CharlesRondo
Frequent Visitor
8 years ago
Solved

Stock prices return graph

Hello, begginer user here! I want to create a line chart with the every day returns of stock prices, the problem for me is that I want it to by dynamic, being able to chose the initial and the end d...
  • v-jiascu-msft's avatar
    v-jiascu-msft
    8 years ago

    Hi CharlesRondo,

     

    In your scenario, you may need three or more date tables due to the start dates are different and independent. Please check out the demo in the attachment. Three measures are like below. (Please note: only F and GM are the same with your requirements here. You can adjust the FCA yourself.)

    F =
    VAR minDate =
        CALCULATE ( MIN ( Table1[Timestamp] ), ALLSELECTED ( Table1[Timestamp] ) )
    RETURN
        IF (
            MIN ( Table1[Timestamp] ) = minDate,
            0,
            DIVIDE (
                SUM ( Table1[Trade Close] ),
                CALCULATE ( SUM ( Table1[Trade Close] ), 'Table1'[Timestamp] = minDate )
            )
                - 1
        )
    
    GM =
    VAR minDate =
        CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
    RETURN
        IF (
            MIN ( Table1[Timestamp] ) <= minDate,
            0,
            DIVIDE (
                SUM ( Table1[Trade Close .1] ),
                CALCULATE ( SUM ( Table1[Trade Close .1] ), 'Table1'[Timestamp] = minDate )
            )
                - 1
        )
    
    FCA =
    VAR minDate =
        CALCULATE ( MIN ( Table1[Timestamp] ), ALLSELECTED ( Table1[Timestamp] ) )
    RETURN
        IF (
            MIN ( Table1[Timestamp] ) = minDate,
            0,
            DIVIDE (
                SUM ( Table1[Trade Close .2] ),
                CALCULATE ( SUM ( Table1[Trade Close .2] ), 'Table1'[Timestamp] = minDate )
            )
                - 1
        )
    

    Stock_prices_return_graph2

    Best Regards,

    Dale