cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate II
Advocate II

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/20203.0
4/27/20203.0
5/29/20202.0


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
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.

View solution in original post

2 REPLIES 2
Highlighted
Super User V
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.

View solution in original post

Highlighted
Advocate II
Advocate II

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.

Helpful resources

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