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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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.


Go to My LinkedIn Page


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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