Need to return the total quantity of a product in the last 3 days

supergravy

New Member
Joined
Feb 1, 2017
Messages
4
Have tried searching the forums but can't seem to word my question correctly. Here is a basic table:-

DateTypeProductQty
01/12/2022​
OrderBlue Shirt
1​
02/12/2022​
OrderBlue Shirt
1​
03/12/2022​
OrderBlue Shirt
2​
04/12/2022​
OrderYellow Shirt
1​
05/12/2022​
OrderBlue Shirt
1​
06/12/2022​
OrderYellow Shirt
2​
07/12/2022​
OrderBlue Shirt
3​
07/12/2022​
OrderBlue Shirt
1​

On another sheet I want see how many blue shirts have sold in the last 3 days, but am unsure if this can be done with a formula:-

ProductSold in last few days
Blue Shirt5
Yellow Shirt2
Pink Shirt0

Any helps would be greatly appreciated.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I would use SUMPRODUCT, but first you need a value to define the last few days.

In my example below, the data range is in D2:G17, including labels, so the first data begins on row 3.

I put the formula for the current date =NOW() in I3 which gives me 12/7/2022.

Next to that cell I input a value that represents the last few days, so for the last three days I input 3 in J3.

Next to that cell in K3 I input the formula =DATE(YEAR(I3-J3+1),MONTH(I3-J3+1),DAY(I3-J3+1)) , which displays 12/5/2022, so my days range to count is Dec 5th through Dec 7th. I tried a simple subtraction I3 - J3 first, which also displayed 12/5/2022, but the results explained below were always off a day, so I changed it to the formula above to be precise.

Next to the first product to count, Blue Shirt for example, in cell J6 I input the following formula, and copied it down through K8.

=SUMPRODUCT(--($F$3:$F$17=I6),--($D$3:$D$17>=$K$3),$G$3:$G$17)

It's basically saying for all the Products in F3:F17 that equal the product input to the left in column I, and for all the dates in D3:D17 that fall in the past 3 days (as identified in J3), in this example 12/5/2022 to 12/7/2022, add up the Qty's in the data range.

DateTypeProductQty
12/7/2022OrderBlue Shirt112/7/2022
3​
12/5/2022​
12/6/2022OrderPink Shirt3
12/6/2022OrderBlue Shirt2ProductSold in last few days
12/6/2022OrderYellow Shirt1Blue Shirt
10​
12/5/2022OrderBlue Shirt1Yellow Shirt
4​
12/5/2022OrderYellow Shirt2Pink Shirt
5​
12/5/2022OrderBlue Shirt3
12/5/2022OrderPink Shirt2
12/5/2022OrderBlue Shirt1
12/5/2022OrderYellow Shirt1
12/5/2022OrderBlue Shirt2
12/3/2022OrderBlue Shirt3
12/3/2022OrderBlue Shirt3
12/3/2022OrderYellow Shirt1
12/2/2022OrderBlue Shirt3
 
Upvote 0
A way if you have some of the newer dynamic array formulas.

SG.xlsx
ABCDEFG
1DateTypeProductQtyProductQuantity
212/1/2022OrderBlue Shirt1Blue Shirt7
312/1/2022OrderBlue Shirt1Yellow Shirt6
412/2/2022OrderBlue Shirt2Pink Shirt5
512/2/2022OrderYellow Shirt1
612/3/2022OrderBlue Shirt1
712/4/2022OrderYellow Shirt2
812/4/2022OrderBlue Shirt3
912/5/2022OrderBlue Shirt1
1012/5/2022OrderPink Shirt2
1112/6/2022OrderPink Shirt3
1212/6/2022OrderYellow Shirt4
1312/7/2022OrderBlue Shirt3
Sheet2
Cell Formulas
RangeFormula
F1:G4F1=LET(p,UNIQUE(Table1[Product]),s,SUMIFS(Table1[Qty],Table1[Product],p,Table1[Date],">="&TODAY()-3),VSTACK({"Product","Quantity"},HSTACK(p,s)))
A6:A7A6=A5+1
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top