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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sidds_sriv
Regular Visitor

Last 2 weeks sales

Hi,

 

I have a sales data on daily basis for each store-sku combinations....From this i am creating weekly report. For each week, we are taking sum of sales, etc...The data start from week number 6.

 

Now for each I would like calculate the Last 2 weeks sales. For example for week 8 i want to calculate the sales of week 6,and 7.  For week 9, i want to calculate the sales of week 7 and 8 ...so on and on...

 

Need Help on how to have this data in the report.

 

Thanks and Regards

Siddhartha Srivastava

 

 

 

1 ACCEPTED SOLUTION
AlexChen
Microsoft Employee
Microsoft Employee

Hi,

 

For example,  Your sales table is like below:

 

4.png

 

You can create a measure to calculate the sum of salesAmount of weeknum 6 and 7:

 

 last2WeeksAmount = CALCULATE(sumx(sales, sales[salesAmount]),Filter(ALL(sales), sales[weeknum]=max(sales[weeknum])-1 || sales[weeknum] = MAX(sales[weeknum])-2))

 

5.png

 

Best Regards

Alex

 

 

View solution in original post

6 REPLIES 6
AlexChen
Microsoft Employee
Microsoft Employee

Hi,

 

For example,  Your sales table is like below:

 

4.png

 

You can create a measure to calculate the sum of salesAmount of weeknum 6 and 7:

 

 last2WeeksAmount = CALCULATE(sumx(sales, sales[salesAmount]),Filter(ALL(sales), sales[weeknum]=max(sales[weeknum])-1 || sales[weeknum] = MAX(sales[weeknum])-2))

 

5.png

 

Best Regards

Alex

 

 

How does this behave for the first week of the year? 

 

Thanks

Thanks,
Victor Rocca | www.victorrocca.com

Thanks Alex, it worked...really appreciated...

 

Just wanted to know if I need to caclulate Last 2 week sales for a particular product/category...for example for Car/Gun then how should i change the query.

MattAllington
Community Champion
Community Champion

You need a calendar table with a unique Week ID column. Read about that here 

http://exceleratorbi.com.au/power-pivot-calendar-tables/

 

As as long as you have a unique week ID column, you can write a formula like this 

 

Last 2 Weeks :=
CALCULATE (
[Total Sales],
FILTER (
ALL ( Calendar ),
Calendar[WeekID] >= MAX ( Calendar[WeekID] ) -1
&& Calendar[WeekID] <= MAX ( Calendar[WeekID] )
)
)



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Awsome, That was a cool trick Matt!!!

I used used your logic to calculate Current Week Measure:

 

CALCULATE(
'TableQuery'[Sales US($)],
FILTER (
ALL ( 'Sales US($)' ),
[TableQuery] >= MAX ( 'TableQuery'[Fiscal Year and Week] )
))

Thanks Matt , it worked....

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.