Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Month over month Flag

I have a flag called Last Month which is written as follows :   Last Month = IF(YEAR ('Date'[Date])= YEAR(NOW())         && MONTH ('Date'[Date] )=MONTH(NOW())- 1,     1,     0 )     The outpu...
  • Anonymous's avatar
    Anonymous
    8 years ago
    LastMonth =
    VAR CD =
        MAXX ( 'Date', 'Date'[Date] )
    VAR LMM = MONTH ( CD )
    VAR LMY = YEAR (CD)
    RETURN
        IF ( MONTH ( 'Date'[Date] ) = LMM && YEAR ( 'Date'[Date] ) = LMY, 1, 0 )

     

    The formula above will mark 1 on the data of latest month available in your table. Till 4th of October (before September data is loaded), the formula above will mark 1 on August data. After the September data is loaded, it will mark 1 on September data.

     

    If you want to go back one month, use EDATE(CD,-1) instead of CD in the above formula.

    Similarly, If you want to go back two months, use EDATE(CD,-2) instead of CD in the above formula.

     

    You may use an if condition, if you want to automatically determine if it's -1 or -2 or 0 using a variable.

     

    Based on your requirement, you may modify it.

  • Anonymous's avatar
    Anonymous
    8 years ago

     

    I modified it slightly

     

    2 MONTHS BACK TRIAL =
    
    VAR CD = MAXX('DATE','DATE'[DATE])
    VAR AF = IF(MONTH(CD) < MONTH(TODAY()),-1,-2)
    VAR LMM = MONTH(EDATE(CD,AF))
    VAR LMY = YEAR(EDATE(CD,AF))
    RETURN
    IF (MONTH('Date'[DATE])=LMM && YEAR['Date'[Date])=LMY,1,0)
  • Anonymous's avatar
    Anonymous
    8 years ago

     

    You have to subtract one from both 0 and -1 and make it -1 and -2