Forum Discussion

AmalrajRRD1's avatar
AmalrajRRD1
Helper II
9 years ago
Solved

DAX

Hi all, 

 How to do Privous month calculation like i have current month (100)-privous month (50) = 50

how to do in dax.. 

 

Thanks

  • Hey,

     

    do you have a separate Calendar table, if not you should ;-) And make sure both tables are related properly.

     

    Then you should give PREVIOUSMONTH a try like so:

    CALCULATE(SUM('yourtable'[yournumericcolumn]), PREVIOUSMONTH('calendar'[Date]))

    Here you will find almost everything about time intelligence with DAX:

    http://www.daxpatterns.com/time-patterns/

     

    If you are new to the sometimes mind-boggling DAX statements I would wholeheartedly recommend the following books

     also in this sequence

    1. Analyzing Data with Microsoft Power BI and Power Pivot for Excel
    2. Dax Patterns 2015
    3. The Definitive Guide to DAX

    All three have been written by Marco Russo and Alberto Ferrari

     

    Hope this gets you started 

  • TomMartens's avatar
    TomMartens
    9 years ago

    The subtraction can look like this

     

    CALCULATE(SUM('yourtable'[yournumericcolumn])) - CALCULATE(SUM('yourtable'[yournumericcolumn],PREVIOUSMONTH('calendartable'[date]))

     

    Cheers

9 Replies

  • Hey,

     

    do you have a separate Calendar table, if not you should ;-) And make sure both tables are related properly.

     

    Then you should give PREVIOUSMONTH a try like so:

    CALCULATE(SUM('yourtable'[yournumericcolumn]), PREVIOUSMONTH('calendar'[Date]))

    Here you will find almost everything about time intelligence with DAX:

    http://www.daxpatterns.com/time-patterns/

     

    If you are new to the sometimes mind-boggling DAX statements I would wholeheartedly recommend the following books

     also in this sequence

    1. Analyzing Data with Microsoft Power BI and Power Pivot for Excel
    2. Dax Patterns 2015
    3. The Definitive Guide to DAX

    All three have been written by Marco Russo and Alberto Ferrari

     

    Hope this gets you started 

      • TomMartens's avatar
        TomMartens
        Super User

        No, my example just gets you to calculate the value for the previous month, finally you have to do the subtraction :-)