Forum Discussion

stella1215's avatar
stella1215
Frequent Visitor
5 years ago
Solved

Calculate daily return rate

hello everyone!

 

I want to add a calculated column of the daily return rate by the company. My data looks like below. I want to use today's price divided by yesterday's price, and so on. For example, 2021.4.7's price / 2021.4.6's price. How can I achieve this?

 

Thank you!

 

DatecompanyPrice
2021.4.66000018.51
2021.4.76000019.41
2021.4.86000019.1
2021.4.66000029.88
2021.4.760000210.78
2021.4.860000210.52
2021.4.660000310.62
2021.4.760000310.32
2021.4.860000310.43
  • Jihwan_Kim's avatar
    Jihwan_Kim
    5 years ago

    Hi, stella1215 

    Please check the below picture and the sample pbix file's link down below.

     

     

    Daily Return Rate Measure =
    VAR currentdate =
    MAX ( Data[Date] )
    VAR currentcompany =
    MAX ( Data[company] )
    VAR previousdate =
    CALCULATE (
    MAX ( Data[Date] ),
    FILTER ( ALLEXCEPT ( Data, Data[company] ), Data[Date] < currentdate )
    )
    VAR previousprice =
    CALCULATE ( [Today Price], Data[Date] = previousdate )
    RETURN
    DIVIDE ( [Today Price], previousprice, BLANK () )

     

     

    https://www.dropbox.com/s/oi2fqd0cn62e0gq/stella1215.pbix?dl=0 

     

    Hi, My name is Jihwan Kim.

    If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

4 Replies

  • Hi, stella1215 

     

    Please try the below calculated column.

     

    Daily Return Rate Column =
    DIVIDE (
    Data[Price],
    VAR previousdate =
    CALCULATE (
    MAX ( Data[Date] ),
    FILTER (
    ALLEXCEPT ( Data, Data[company] ),
    Data[Date] < EARLIER ( Data[Date] )
    )
    )
    RETURN
    CALCULATE (
    SUM ( Data[Price] ),
    FILTER ( ALLEXCEPT ( Data, Data[company] ), Data[Date] = previousdate )
    ),
    BLANK ()
    )

     

    Hi, My name is Jihwan Kim.

    If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

    • stella1215's avatar
      stella1215
      Frequent Visitor

      Thank you for your help! I have another question: is it possible to achieve this in a measure? I applied your DAX to get that calculated column. Since my dataset is kinda big, it slowed down the entire report compared to when I directly import the return rate. I was wondering if making it a measure can do the same trick and speed the loading process?

      • Jihwan_Kim's avatar
        Jihwan_Kim
        Icon for Super User rankSuper User

        Hi, stella1215 

        Please check the below picture and the sample pbix file's link down below.

         

         

        Daily Return Rate Measure =
        VAR currentdate =
        MAX ( Data[Date] )
        VAR currentcompany =
        MAX ( Data[company] )
        VAR previousdate =
        CALCULATE (
        MAX ( Data[Date] ),
        FILTER ( ALLEXCEPT ( Data, Data[company] ), Data[Date] < currentdate )
        )
        VAR previousprice =
        CALCULATE ( [Today Price], Data[Date] = previousdate )
        RETURN
        DIVIDE ( [Today Price], previousprice, BLANK () )

         

         

        https://www.dropbox.com/s/oi2fqd0cn62e0gq/stella1215.pbix?dl=0 

         

        Hi, My name is Jihwan Kim.

        If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.