Forum Discussion

uthall's avatar
uthall
Helper II
9 years ago
Solved

Previous Month

Hello,

 

I have a table with data and dates.

 

I simply want to show a card of the last 1 months data.

 

What is the DAX syntax for this?

 

Thanks

Jeff

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Typically, you would create a column like so:

     

    Column = MONTH(TODAY()) - MONTH(Table[Date])

    And then just filter to 1 or 2 depending upon your definition of "last".

    • uthall's avatar
      uthall
      Helper II

      Thanks,

       

      What if TODAY() is Jan 2017, making the previous month DEC 2016?

       

      The return value will be 1-12 = 11 (seems to be an absolute value)

       

      This is also the case if i want Next Month, which is tghe reverse of the above

       

      Any further ideas?

       

       

      • aaronseaman's avatar
        aaronseaman
        New Member

        G'day, 

         

        I have used the following formula in Excel to identify the previous month,  it works also for January.

         

        =IF(MONTH(TODAY())=MONTH(1),IF(AND(MONTH(C13)=MONTH(TODAY())+11,YEAR(C13)=YEAR(TODAY())-1),1,0),IF(AND(MONTH(C13)=MONTH(TODAY())-1,YEAR(C13)=YEAR(TODAY())),1,0))

         

        This formula, however, is not working in Power BI, if anyone can enlighten me to why i would appreciate it.