cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Uzi2019
Helper V
Helper V

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?
 
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.

View solution in original post

amitchandak
Super User IV
Super User IV

@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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

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

Jihwan_Kim
Community Champion
Community Champion

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.

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

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Top Solution Authors
Top Kudoed Authors