Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
anandav
Skilled Sharer
Skilled Sharer

DATESINPERIOD calculation question

Hi All,

 

Below is my data:

CompnayDateAmount
A01/01/201810
B01/01/201820
B02/01/201820
A01/02/201830
A01/02/201810
B02/02/201840
B03/02/201850
A01/03/201850
B01/03/201860
A01/04/201870
A01/04/201850
A02/04/201840
A03/04/201870
B04/04/201880
A01/05/201890
B01/05/2018100
A01/06/2018110
B01/06/2018120
B02/06/2018130
B03/06/2018140
B04/06/2018140
B05/06/2018150
B06/06/2018160

 

I am using the following DAX formula to calculate moving / rolling average for the past 2 months.

Past X Months Average =
CALCULATE(
    AVERAGE(PrevMonth[Amount]),
    DATESINPERIOD(PrevMonth[Date],
        LASTDATE(PrevMonth[Date]),
        -2, 
        MONTH
    )
)

 

When I use the date with no heirarchy I get the correct result for the last day of the month.

 

Untitled.png

 

But when I try to use the date hierarchy and display the year and month with the average, it is not giving the correct results.

Capture.JPG

 

Any suggestion why this is happening?

 

I do not have a calendar table.

 

Any help will be much appreciated.

1 ACCEPTED SOLUTION
anandav
Skilled Sharer
Skilled Sharer

I figured out that I need to have a calendar table to solve the above problem.

 

If anyone is interested in the solution please see this blog.

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi 

Thank you for sharing !

 

Best Regards

Maggie

anandav
Skilled Sharer
Skilled Sharer

I figured out that I need to have a calendar table to solve the above problem.

 

If anyone is interested in the solution please see this blog.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors