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
Anonymous
Not applicable

How to get Last Week, Last One Month, Last Three Month, Last Year sales based on Weekending Dates

How to get sales of Last Week, Last One Month, Last Three Month, Last Year sales based on selected weekending dates from slicer filter. By using DATESINPERIOD function I'm getting results for last week but when I'm using same function for last 1 Month, 3 Months, 6 Months & 1 Year it is giving me blank values. How to get values for this particular month.

 

This is how I'm doing my calculation. 

 

 

Last Week % = DIVIDE(CALCULATE([MTV],DATESINPERIOD(DimDate[Date],SELECTEDVALUE(DimDate[WeekEndingDate]),-7,DAY)),[Old_Cost])

 

 

 

It is giving me results for last week but not for previous months which I wanted.
Note: In my slicer I'm using WeekEnding Dates which look like these 22/01/2023, 15/01/2023, 08/01/20223.
Any help would be greatly appreciated. Thank you.
@Ashish_Mathur 

7 REPLIES 7
Ashish_Mathur
Super User
Super User

So if the date selected in 15/1/2023, then what period should be considered for "Last 1 month"?  Also, share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

For Last One Month 2022 December.
For 3 Months 2022 October
For 6 Months 2022 July
Here I'm attatching PBI file https://we.tl/t-j74qRll07w 

This pattern should work for 1 prior month

P1_Month_1 = 
VAR EFF_Price = 
            [OP] +
                DIVIDE([CP],SUM(LData[TermPeriod])+[RP])
VAR Prior_Price = 
            [GP] +
                DIVIDE([RP],SUM(LData[TermPeriod])+[Total_QC])
VAR Result  = EFF_Price-Prior_Price

Return
    DIVIDE(
        CALCULATE(
            Result,
            datesbetween(DimDate[Date],eomonth(min(DimDate[WeekEndingDate]),-2)+1,eomonth(min(DimDate[WeekEndingDate]),-1))
            ),
            Prior_Price
        )

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Getting same results for last one week & last one monthimage.png

Check your data please.  May be it is such that the result for previous week and previous month are the same. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
TomMartens
Super User
Super User

Hey @Anonymous ,

 

I recommend reading this article, it contains almost everything regarding date/datetime calculations: Time patterns – DAX Patterns

Maybe you have to remove the existing filter context coming from the slicer selection if you are time-traveling backwards.
Wondering what the previous month will be, because a Calendar week can touch two months.
Please consider using the code sample tag in the future as DAX/M is more readable then:
image.png
Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Last Week % = DIVIDE(CALCULATE([MTV],DATESINPERIOD(DimDate[Date],SELECTEDVALUE(DimDate[WeekEndingDate]),-7,DAY)),[Old_Cost])

This is the logic which I'm currently using it working for last week but not for Last 1,3,6 Months

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.