Forum Discussion

RashmitaR's avatar
RashmitaR
Helper IV
10 years ago

Dax

Hi ,

I have a dataset with one of its column as date and one more as close price ,I wanted to find the average of close price for the last 7 dates present in my date column for every row.For eg

DateClose Price7Day15Day30day
8-Apr-1614.1214.1113.6566713.81167
7-Apr-1614.2414.0813.6186713.781
6-Apr-1614.0613.8842913.5906713.75133
5-Apr-1613.7813.7328613.6006713.721
4-Apr-1614.2713.6842913.62213.705
1-Apr-1614.1513.5657113.6206713.67433
31-Mar-1614.1513.4042913.64613.661
30-Mar-1613.9113.2428613.66813.66433
29-Mar-1612.8713.1671413.7406713.654
28-Mar-161313.2642913.8833313.655
23-Mar-1613.4413.3814313.93613.67833
22-Mar-1613.4413.4914313.9406713.73533
21-Mar-1613.0213.5857113.9446713.81233
18-Mar-1613.0213.7614313.9633313.90333

 

Thanks,

Rashmita Reddy

4 Replies

  • Sean's avatar
    Sean
    Community Champion

    RashmitaR This Measure should work... Let me know.

     

    7 Day Avg =
    DIVIDE (
        CALCULATE (
            SUM ( Table[Close Price] ),
            DATESINPERIOD ( Table[Date], LASTDATE ( Table[Date] ), -7, DAY )
        ),
        CALCULATE (
            DISTINCTCOUNT ( Table[Date] ),
            DATESINPERIOD ( Table[Date], LASTDATE ( Table[Date] ), -7, DAY )
        ),
        0
    )

     

    • achinm45's avatar
      achinm45
      Advocate IV

      Hi Sean,

      Thanks for perspective. However dates are not contigous :)

       

      BR,
      Achin

       

    • RashmitaR's avatar
      RashmitaR
      Helper IV

      Thank you for reply. I have created a column using your suggestion but while creating another one for 15day average i am getting a circular dependency hence i am unable to create it . Could you please help me by letting me know how to deal with this issue .

       

      Thanks ,

      Rashmita Reddy.

  • Hi RashmitaR

    Try following :

     

    1 ) Create an Index column by going into Power Query part of Power BI (click Edit Queries) and then under transformmations.

    2) Then write formula as in screenshot here :

     

    3) Write similarly for other metrics

     

    Cheers !

    Achin