Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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.0 |
4/27/2020 | 3.0 |
5/29/2020 | 2.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
Solved! Go to Solution.
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.
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.
User | Count |
---|---|
40 | |
26 | |
22 | |
16 | |
15 |
User | Count |
---|---|
54 | |
35 | |
18 | |
17 | |
15 |