Forum Discussion

Janaki's avatar
Janaki
Regular Visitor
9 years ago
Solved

dax previousmonth

Hi,

 

I am trying use PREVIOUSMONTH to get the previous month value. My data looks like this

 

 

I calculated previous from current value using PREVIOUSMONTH, but i get one extra month March 2017.

Previousvalue =
CALCULATE(
'xyz'[CurrentValue],
PREVIOUSMONTH('xyz'[ReportDate].[Date]))

 

Can someone help me understand why am i getting March, though my date column stops at feb 2017?  Thank you,


  • Janaki wrote:

    Hi,

     

    Thank you. The currentvalue that I am using is a measure. Would you have a alternate suggestion? 


    Janaki

    Then just try

    Previousvalue =
    IF (
        ISBLANK ( MAX ( xyz[ReportDate] ) ),
        BLANK (),
        CALCULATE (
             'xyz'[CurrentValue],
            PREVIOUSMONTH ( dimdate[Date].[Date] )
        )
    )

3 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    Janaki wrote:

    Hi,

     

    I am trying use PREVIOUSMONTH to get the previous month value. My data looks like this

     

     

    I calculated previous from current value using PREVIOUSMONTH, but i get one extra month March 2017.

    Previousvalue =
    CALCULATE(
    'xyz'[CurrentValue],
    PREVIOUSMONTH('xyz'[ReportDate].[Date]))

     

    Can someone help me understand why am i getting March, though my date column stops at feb 2017?  Thank you,


    Janaki

    It seems by design. If you don't like it, try to apply some tricks as

    Previousvalue =
    IF (
        ISBLANK ( MAX ( xyz[ReportDate] ) ),
        BLANK (),
        CALCULATE (
            SUM ( 'xyz'[CurrentValue] ),
            PREVIOUSMONTH ( dimdate[Date].[Date] )
        )
    )
    • Janaki's avatar
      Janaki
      Regular Visitor

      Hi,

       

      Thank you. The currentvalue that I am using is a measure. Would you have a alternate suggestion? 

      • Eric_Zhang's avatar
        Eric_Zhang
        Microsoft Employee

        Janaki wrote:

        Hi,

         

        Thank you. The currentvalue that I am using is a measure. Would you have a alternate suggestion? 


        Janaki

        Then just try

        Previousvalue =
        IF (
            ISBLANK ( MAX ( xyz[ReportDate] ) ),
            BLANK (),
            CALCULATE (
                 'xyz'[CurrentValue],
                PREVIOUSMONTH ( dimdate[Date].[Date] )
            )
        )