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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Uzi2019
Super User
Super User

Incorrect Previous month value calculation

Hi Community,

 

I am trying to create previous month values. Everything is working as expected only issue is last date in Database is 5th April 2021 but when I select Date range slicer from 1st to 4th April so it gives me correct prevoius month value. BUT when I select date range from 1st April to 5th April so it gives me whole March value in previous measure.

 

I want it to give me 1st to 5th March value in my previous measure when I select date range from 1st to 5th April.

 

I don't know why it's behaving like this.

 

Previous Sales = CALCULATE(SUM(DataTable[Sales]),DATEADD('Calendar'[Date],-1,MONTH))
 
Can anyone please help me in this?
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!
2 ACCEPTED SOLUTIONS
v-lionel-msft
Community Support
Community Support

Hi @Uzi2019 ,

 

Did you create a relationship between the two tables?

v-lionel-msft_0-1617849275058.png

 

v-lionel-msft_1-1617849294348.png

v-lionel-msft_2-1617849320402.png

 

Best regards,
Lionel Chen

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

v-kkf-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

I create the following sample data, and then create a measure.

v-kkf-msft_0-1617936063423.png

 

Ventas anteriores = 
var MonthEnd = 
    CALCULATE(
        SUM('DataTable'[Sales]),
        DATEADD( 'Calendar'[Date], -1, MONTH )
    )
var Month = 
    CALCULATE(
        SUM('DataTable'[Sales]),
        FILTER(
            ALL('DataTable'),
            'DataTable'[Date] <= EDATE( MAX('Calendar'[Date]), -1 )
            &&'DataTable'[Date] >= EDATE( MIN('Calendar'[Date]), -1 )
        )
    )
var Result = 
    IF(
        MAX('Calendar'[Date]) = EOMONTH( MAX('Calendar'[Date]), 0 ), 
        MonthEnd, 
        Month
    )
return Result

 

image.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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-kkf-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

I create the following sample data, and then create a measure.

v-kkf-msft_0-1617936063423.png

 

Ventas anteriores = 
var MonthEnd = 
    CALCULATE(
        SUM('DataTable'[Sales]),
        DATEADD( 'Calendar'[Date], -1, MONTH )
    )
var Month = 
    CALCULATE(
        SUM('DataTable'[Sales]),
        FILTER(
            ALL('DataTable'),
            'DataTable'[Date] <= EDATE( MAX('Calendar'[Date]), -1 )
            &&'DataTable'[Date] >= EDATE( MIN('Calendar'[Date]), -1 )
        )
    )
var Result = 
    IF(
        MAX('Calendar'[Date]) = EOMONTH( MAX('Calendar'[Date]), 0 ), 
        MonthEnd, 
        Month
    )
return Result

 

image.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Syndicate_Admin , You can try like example

 

MTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALMTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))


LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

LYMTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

Refer

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

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
v-lionel-msft
Community Support
Community Support

Hi @Uzi2019 ,

 

Did you create a relationship between the two tables?

v-lionel-msft_0-1617849275058.png

 

v-lionel-msft_1-1617849294348.png

v-lionel-msft_2-1617849320402.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi, @Uzi2019 

If it is OK with you, please share your sample pbix file, then I can try to look into it and come up with a fixed result. 

 

Thank you.

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you for reply. But cant share you pbix file for security reasons.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors