Forum Discussion
Countrows for previousmonth
- 2 years ago
pls try this
Measure= VAR _Start =EOMONTH( TODAY(),-2)+1 VAR _End = EOMONTH( TODAY(),-1) RETURN CALCULATE( COUNTROWS(Data), USERELATIONSHIP(Data[Created], 'Calendar'[Date]), DATESBETWEEN('Calendar'[Date] ,_Start,_End )
pls try this
Measure=
VAR _Start =EOMONTH( TODAY(),-2)+1
VAR _End = EOMONTH( TODAY(),-1)
RETURN
CALCULATE(
COUNTROWS(Data),
USERELATIONSHIP(Data[Created], 'Calendar'[Date]),
DATESBETWEEN('Calendar'[Date] ,_Start,_End
)
Thank you Ahmedx
This code now returns the figure that I am expecting.
However, I would be interested to know if somebody could explain why a function exists called PREVIOUSMONTH (https://dax.guide/previousmonth/) that I would have thought could have been used to get to my answer, but instead we have to use code and manipulate it in such a way to go back and forth in time. Just curious 🙂
Thank you all for your help, lots to learn !
Dean
- Ahmedx2 years agoSuper User
to understand how PREVIOUSMONTH works watch this video
- Ahmedx2 years agoSuper User
try this
VAR _Start =EOMONTH( TODAY(),-1)+1 VAR _End = EOMONTH( TODAY(),0) RETURN CALCULATE( COUNTROWS(Data), USERELATIONSHIP(Data[Created], 'Calendar'[Date]), PREVIOUSMONTH(FILTER(ALL('Calendar'[Date]), 'Calendar'[Date] >= _Start && 'Calendar'[Date] <= _End)))- DeanStearn2 years agoNew Member
Thank you Ahmedx , much appreciated
- AllisonKennedy2 years agoCommunity Champion
DeanStearn Time intelligence functions are a bit mind boggling at first - I think it took me a few years to fully grasp the ins and outs of them. Lots of testing and trial and error. You can use the Previous Month function, and it will give you the ENTIRE month, not just the dates you have selected, following my same pattern:
PreviousMonthOpenTickets =CALCULATE([Total Created Tickets],PreviousMonth('Calendar'[Date]))The filtering for the date range that you were trying to do with the < filters within the DAX code actually happens in the visual / report layer, rather than needing to be applied in the DAX itself.