Forum Discussion

Larry130's avatar
Larry130
Frequent Visitor
9 years ago
Solved

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 ...
  • v-ljerr-msft's avatar
    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