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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
OKgo
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
lbendlin
Super User
Super User

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
lbendlin
Super User
Super User

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.

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors