Forum Discussion
Larry130
9 years agoFrequent Visitor
Current month vs Previous month
Hi! Could you guys give some help? I'm struggling here. I need to do a calculation between the current x last month, but I'll not use a date dimension to show each month in a table/graph. Because ...
- 9 years ago
Hi Larry130,
If I understand you correctly, the formula below should work in your scenario. :smileyhappy:
PrevMonth = VAR currentMonth = MONTH ( TODAY () ) VAR currentYear = YEAR ( TODAY () ) RETURN IF ( currentMonth = 1, CALCULATE ( [ID Alert], FILTER ( ALL ( 'Calendar'[Date] ), YEAR ( 'Calendar'[Date] ) = currentYear - 1 && MONTH ( 'Calendar'[Date] ) = 12 ) ), CALCULATE ( [ID Alert], FILTER ( ALL ( 'Calendar'[Date] ), YEAR ( 'Calendar'[Date] ) = currentYear && MONTH ( 'Calendar'[Date] ) = currentMonth - 1 ) ) )Regards
v-ljerr-msft
9 years agoMicrosoft Employee
Hi Larry130,
If I understand you correctly, the formula below should work in your scenario. :smileyhappy:
PrevMonth =
VAR currentMonth =
MONTH ( TODAY () )
VAR currentYear =
YEAR ( TODAY () )
RETURN
IF (
currentMonth = 1,
CALCULATE (
[ID Alert],
FILTER (
ALL ( 'Calendar'[Date] ),
YEAR ( 'Calendar'[Date] )
= currentYear - 1
&& MONTH ( 'Calendar'[Date] ) = 12
)
),
CALCULATE (
[ID Alert],
FILTER (
ALL ( 'Calendar'[Date] ),
YEAR ( 'Calendar'[Date] ) = currentYear
&& MONTH ( 'Calendar'[Date] )
= currentMonth - 1
)
)
)
Regards
Larry130
9 years agoFrequent Visitor
PERFECT! Thanks v-ljerr-msft
I've tried to use the SQLBI DAX Pattern for previous month, but was really hard to understand. Your way of doing it using VAR was way easier to understand. I'll study VAR!