Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Previous Month not working

Hi there,
Please take a look at the attachment. (transactions are based on year and month)
I'm debuging my measure and testing the PreviousHours VAR
The VAR totalHours work fine

The Previousmonth function working fine

But when I combine them together it show blank records?
What cause it to show blank and how do I fix that?

Thanks,

Oded Dror

 

5 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Greg,

       

      Thank you for your response, It looks like my table is too complex for thease two functios  (even with adding more selected values as filters)
      I tested on very simple table 12 months 01/31/2020 - 12/31/2020 as EOM date and amount 100  - 1200 both Previousmonth and Dateadd functions works.

      but did not work on my table. so for fast solution I duplicate the table with current period and previous period and attach

      the curent period to the previous periods along with company department job and datekey and it works as expected.

      I did not test the earlier function yet (when I have time I will).

      Thanks again,

      Oded Dror

       

  • Always use a date table in such cases. See my examples

    MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
    last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
    last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
    last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
    last year MTD Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
    last QTR same Month (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,Qtr))))
    MTD (Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR('Date'[Date])))
    MTD (Last Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR(dateadd('Date'[Date],-12,MONTH),"8/31")))
    
    

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Amit,

      Thank you for your response, please see my reply to Greg.

       

      Thank you,

      Oded Dror

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        My pleasure Anonymous let me know if you need anything further. But, it is very difficult to really be specific when helping without sample test data.