cancel
Showing results for
Did you mean:
Highlighted

## 60 day (and full 2 month) average question

Unsure if I should use a measure or helper column. At the moment it is a helper colum. [Date] is linked to a calendar table.

Last 60 day Average:=
DIVIDE (
CALCULATE (
SUM ( [Quantity] ),
DATESINPERIOD ( 'Table1'[Date], NOW (), -60, DAY )
),
2
)

Where today is 6/6/2020 the first data point is out of scope and the measure returns 2.5 which is fine (3 + 2 divided by 2)

 4/3/2020 3 4/27/2020 3 5/29/2020 2

How would I go about upgrading the DAX to consider full months? For example April and May? Both EOMONTH dax formula return the correct dates (as helper columns).

EOMONTH('Dispensing Merge All Studies'[Disp Date],-3)+1

EOMONTH ( 'Dispensing Merge All Studies'[Disp Date], -1)

I am struggling to weave this into the DAX with DATESINPERIOD or DATESBETWEEN. Any pointers would be most apprecated

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User V

## Re: 60 day (and full 2 month) average question

Remember that you are in the filter context when you start the measure computation.  To get these EOMONTH dates you need to escape from that, for example using CALCULATE().  Create two variables that identify the start and end date of your range, and then use these instead of NOW() and NOW()-60 - Use DATESBETWEEN() for that.

Philosophically this also equates to a calculated column, either in DAX or in Power Query. So an alternative solution would be to add a flag to your Dates table that marks all the days of the previous two months, each time you refresh your dataset.

2 REPLIES 2
Highlighted
Super User V

## Re: 60 day (and full 2 month) average question

Remember that you are in the filter context when you start the measure computation.  To get these EOMONTH dates you need to escape from that, for example using CALCULATE().  Create two variables that identify the start and end date of your range, and then use these instead of NOW() and NOW()-60 - Use DATESBETWEEN() for that.

Philosophically this also equates to a calculated column, either in DAX or in Power Query. So an alternative solution would be to add a flag to your Dates table that marks all the days of the previous two months, each time you refresh your dataset.

Highlighted

## Re: 60 day (and full 2 month) average question

Agh I see. The filter context reminder was helpful. Creating the variable and using CALCULATE sort of caches the EOMONTH answers like the way a helper column would for the purpose of the measures being able to call on them later.

Announcements

#### August Community Highlights

Check out a full recap of the month!

#### August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

#### Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors