Forum Discussion
DeanStearn
2 years agoNew Member
Countrows for previousmonth
Hi, hopefully somebody can help me with this. I am trying to get a count of all rows for the previous month and have tried different solutions. There are similar posts to this problem, but none o...
- 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 )
DeanStearn
2 years agoNew Member
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
Ahmedx
2 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