Forum Discussion

Laocsulak's avatar
Laocsulak
Icon for Helper I rankHelper I
3 years ago
Solved

Get last months from a table

I have a table like this:

 

I need to get a table with just the last month information. So in this example, it would be dates just since 26/11/2022.

 

I have tried 

Date_Goal = CALCULATETABLE('Date',DATESINPERIOD('Date'[date],MAX('Date'[date]),-1,MONTH))
 
But it doesn't give me the desired result:

 

Dummy tables:

https://drive.google.com/drive/folders/10nBzXYPfSuO87Sjl4_BkOdC2kVxQuDai?usp=share_link

 

Anyone could help me with this DAX expression? Thanks in advance!

 

 

 

 

 

 

  • hi Laocsulak 

    try to write the table like this:

    Date_Goal = 
    VAR _maxdate = EDATE( MAX(TableName[Date]), -1) +1 
    RETURN
    CALCULATETABLE(
        TableName,
        TableName[Date]<=_maxdate
    )

2 Replies

  • hi Laocsulak 

    try to write the table like this:

    Date_Goal = 
    VAR _maxdate = EDATE( MAX(TableName[Date]), -1) +1 
    RETURN
    CALCULATETABLE(
        TableName,
        TableName[Date]<=_maxdate
    )
    • Laocsulak's avatar
      Laocsulak
      Icon for Helper I rankHelper I

      Thanks! It solved the problem, changing the last inequality, using >= instead of <=.

       

      Date_Goal =
      VAR _maxdate = EDATE( MAX('Date'[Date]), -1) +1
      RETURN
      CALCULATETABLE('Date','Date'[Date]>=_maxdate)