Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
tracytran91
Helper III
Helper III

Same period of Last month

Hi forks, 

 

Most of time intelligence function are able to get the full MTD of previous month. However, I would like to get only the Same period of Last month.

For example: Today is Nov 24 2020, I want to get the total sale from Oct 1 2020 to Oct 24 2020.   

 

I wrote the DAX to solve this problem. Unfortunately, it raises the error? 

Could you please help me out regarding to this issue? 

Thank you in advance. 

 

Error PMTD.png

 

 

 

 

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @tracytran91 ,

If the dataset does not have a continous Calendar date, not recommend to use date-and-time-functions. Try to create measure like this:

Same period of last month =
VAR currrent =
    TODAY ()
VAR mindate =
    DATE ( YEAR ( currrent ), MONTH ( currrent ) - 1, 1 )
VAR maxdate =
    DATE ( YEAR ( currrent ), MONTH ( currrent ) - 1, DAY ( currrent ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] >= mindate && 'Table'[Date] <= maxdate )
    )

last month.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yingjl
Community Support
Community Support

Hi @tracytran91 ,

If the dataset does not have a continous Calendar date, not recommend to use date-and-time-functions. Try to create measure like this:

Same period of last month =
VAR currrent =
    TODAY ()
VAR mindate =
    DATE ( YEAR ( currrent ), MONTH ( currrent ) - 1, 1 )
VAR maxdate =
    DATE ( YEAR ( currrent ), MONTH ( currrent ) - 1, DAY ( currrent ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] >= mindate && 'Table'[Date] <= maxdate )
    )

last month.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, I used the same solution for a problem. However I have trouble filtering by people. Everyone brings me the same amount of data

My model is as follows:

Captura de pantalla 2022-09-05 165940.png

And this is what the VIZ looks like

Captura de pantalla 2022-09-05 170537.png

Thank for your help! @v-yingjl 

 

amitchandak
Super User
Super User

@tracytran91 , Try like examples with a date table

 

 

Last MTD =CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)))

 

or

 

Last MTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)

// or

//if('Date'[Date]<=_max,CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year))), blank())

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  thank for your suggestion. I tried it but it is for YTD, not last month MTD as I wish 😞 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.