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

Dynamic Date- Past X months data

Hi 

I am working on sales data by month. Every month I get fresh monthly sales data, so I keep appending my query. 

 

For example in November I have data:
Data of company A:

MonthSales
1 Aug 2019100
1 Sep 2019120
1 Oct 2019110

 

Then next month, in December by Query will become,
Data of company A

MonthSales
1 Aug 2019100
1 Sep 2019120
1 Oct 2019130
1 Nov 2019107

 

Now at any point of time, Regardless of the current month, I always want to produce a table with sales for 1) previous month and 3) average sales of the past 3 months.


So my latest table will look like this

CompanyPrevious month ( ie Oct)Previous 3 months avg sales (Aug- Oct)
A130116.66 (ie avg of 130+ 120+110)

 

How can I create measure for Past 3 month sales, using dynamic dates?

For the first column, I successfully used: 
Recent month sales 

 = CALCULATE(SUM('Sheet1'[Sales ]),PREVIOUSMONTH(DATESMTD('Master'[Month])))
 
I can not figure out how to extract the sum of sales for Past 3 months (exclusing the most recent month) dynamically (ie this formula should work even next month when the data is refreshed).
 
Thanks!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi

 

One way is to add a flag on your calendar that marks the last 3 month dates as true and the rest as false(1,0).

Then 

calculate(sum(expression) , Calendar[Past 3 Months Flag] = 1)

 

Let me know if this helps.

Tomas

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi

 

One way is to add a flag on your calendar that marks the last 3 month dates as true and the rest as false(1,0).

Then 

calculate(sum(expression) , Calendar[Past 3 Months Flag] = 1)

 

Let me know if this helps.

Tomas

 

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.

Top Solution Authors