Group number of purchased SKUs by counting customer

blader1989

New Member
Joined
May 6, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm building a report that will group the number of purchased SKUs by counting customer with total sales > 0, I have tried pivot and many ways but I could not get the result as my expectation in attached file so I hope you can help me.

Thank you for your reading time, your help will be most appreciated!!!

Here is my table example
Product NameCustomer CodeBilling DateQtyYearMonthTotal Sales
Product 45
121001076​
08/02/2023​
5​
2023​
2​
864285​
Product 46
121001076​
04/01/2023​
10​
2023​
1​
2033330​
Product 46
121001076​
01/02/2023​
20​
2023​
2​
4066660​
Product 51
121001258​
20/02/2023​
60​
2023​
2​
3914280​
Product 51
121001258​
24/02/2023​
30​
2023​
2​
1957140​
Product 51
121001792​
04/01/2023​
131​
2023​
1​
8546178​
Product 51
121001792​
09/01/2023​
69​
2023​
1​
4501422​
Product 51
121001943​
04/01/2023​
-50​
2023​
1​
-3261900​
Product 51
121001943​
23/02/2023​
50​
2023​
2​
3261900​
Product 44
121002462​
14/01/2023​
10​
2023​
1​
1000000​
Product 44
121002462​
28/02/2023​
20​
2023​
2​
2000000​
Product 46
121002462​
14/01/2023​
10​
2023​
1​
2033330​
Product 46
121002462​
28/02/2023​
20​
2023​
2​
4066660​
Product 46
121002507​
14/01/2023​
20​
2023​
1​
4066660​
Product 51
121002507​
16/02/2023​
20​
2023​
2​
1304760​
Product 46
121002535​
07/02/2023​
4​
2023​
2​
813332​
Product 19
121002730​
13/02/2023​
10​
2023​
2​
985710​
Product 44
121002730​
10/01/2023​
20​
2023​
1​
2000000​
Product 44
121002730​
27/01/2023​
30​
2023​
1​
3000000​
Product 44
121002730​
13/02/2023​
30​
2023​
2​
3000000​
Product 44
121002730​
23/02/2023​
30​
2023​
2​
3000000​
Product 44
121002730​
28/02/2023​
20​
2023​
2​
2000000​
Product 46
121002730​
10/01/2023​
20​
2023​
1​
4066660​
Product 46
121002730​
27/01/2023​
30​
2023​
1​
6099990​
Product 46
121002730​
31/01/2023​
10​
2023​
1​
2033330​
Product 46
121002730​
31/01/2023​
10​
2023​
1​
2033330​
Product 46
121002730​
13/02/2023​
20​
2023​
2​
4066660​
Product 46
121002730​
23/02/2023​
20​
2023​
2​
4066660​
Product 46
121002730​
28/02/2023​
10​
2023​
2​
2033330​
Product 46
121002752​
14/01/2023​
10​
2023​
1​
2033330​
Product 44
121003038​
05/01/2023​
20​
2023​
1​
2000000​
Product 44
121003038​
21/02/2023​
20​
2023​
2​
2000000​
Product 44
121003038​
24/02/2023​
20​
2023​
2​
2000000​
Product 46
121003038​
05/01/2023​
25​
2023​
1​
5083325​
Product 46
121003038​
27/01/2023​
20​
2023​
1​
4066660​
Product 46
121003038​
28/01/2023​
10​
2023​
1​
2033330​
Product 46
121003038​
21/02/2023​
10​
2023​
2​
2033330​
Product 46
121003038​
24/02/2023​
20​
2023​
2​
4066660​
Product 44
121003326​
16/01/2023​
10​
2023​
1​
1000000​
Product 44
121003326​
27/01/2023​
30​
2023​
1​
3000000​
Product 51
121003349​
17/02/2023​
50​
2023​
2​
3261900​
Product 51
121003359​
16/01/2023​
41​
2023​
1​
2674758​
Product 44
121003423​
16/01/2023​
10​
2023​
1​
1000000​
Product 44
121003423​
27/01/2023​
20​
2023​
1​
2000000​
Product 46
121003423​
16/01/2023​
30​
2023​
1​
6099990​
Product 46
121003423​
27/01/2023​
30​
2023​
1​
6099990​
Product 44
121003739​
09/01/2023​
5​
2023​
1​
500000​
Product 44
121003739​
15/02/2023​
5​
2023​
2​
500000​
Product 46
121003739​
09/01/2023​
5​
2023​
1​
1016665​
 

Attachments

  • expect.JPG
    expect.JPG
    75.7 KB · Views: 5

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Not sure if this is what you're after:
I put your sample data into a spreadsheet A1:G50
I created a unique table of Customer codes via the unique function into I2
Excel Formula:
=UNIQUE(B2:B50)
Then copied the month's from the table to the heading, IE J1:K1 became 1 & 2
I then used a formula to count the number of sku's purchased by customer that month.
Excel Formula:
=COUNTIFS($B:$B,$I2,$F:$F,J$1,$D:$D,">0")
And encompassed the range you're wanting to detect.
In Q2 I added the Number of SKU's going from 1 down and used a formula in R2 going across the number of months (You might need to change the start column depending on the number of months in the previous table.
Excel Formula:
=COUNTIF(J$:J$,$Q2)
This returns the table that you requested. Hope that helps.
 
Upvote 1
Thanks for the XL2BB data - makes it much easier. :)

You put the formula in J3 not J2 as suggested. Put it in J2 instead and remove all the formulas from J3 to J9.

Also, since you have a dynamic array formula in I2, change the J2 formula to this, then you do not have to specify the column I range.

Excel Formula:
=BYROW(I2#,LAMBDA(r,IFNA(ROWS(UNIQUE(FILTER(A2:A16,B2:B16=r,NA()))),0)))
 
Upvote 1
the customer code 121002730 when counting purchased product should be 1 because the product 44 purchased by he/she was 0
So the count for customer code 121001943 should also be zero since that code has a negative total sales?

blader1989.xlsm
ABGHIJK
1Product NameCustomer CodeTotal SalesJan
2Product 4412100246210000001210024622
3Product 4412100273020000001210027301should be 1
4Product 44121002730-20000001210030381
5Product 4412100303820000001210010761
6Product 4612100107620333301210025071
7Product 4612100246220333301210027521
8Product 4612100250740666601210017921
9Product 4612100273040666601210019430??
10Product 461210027306099990
11Product 461210027302033330
12Product 461210027302033330
13Product 461210027522033330
14Product 511210017928546178
15Product 511210017924501422
16Product 51121001943-3261900
17
Sheet2
Cell Formulas
RangeFormula
I2:I9I2=UNIQUE(B2:B16)
J2:J9J2=BYROW(I2#,LAMBDA(r,IFNA(ROWS(UNIQUE(FILTER(A2:A16,(B2:B16=r)*(SUMIFS(G2:G16,A2:A16,A2:A16,B2:B16,r)>0),NA()))),0)))
Dynamic array formulas.
 
Upvote 1
Solution
Excel Formula:
=BYROW(I2#,LAMBDA(r,IFNA(ROWS(UNIQUE(FILTER(A2:A16,B2:B16=r,D2:D16=">0",NA()))),0)))
You wanted to only have items with a positive value in D, so you would need to include that in your filter
 
Upvote 1
Glad to see that your question has been resolved, but I would like to offer an alternative solution in case the PIVOTBY function is available.
Code:
=PIVOTBY(B2:B50,TEXT(C2:C50,"mm mmm"),A2:A50,LAMBDA(x,ROWS(UNIQUE(x))),,0,,0,,SUMIF(B:B,B2:B50,G:G)>0)
Book1.xlsx
ABCDEFGHIJKL
1Product NameCustomer CodeBilling DateQtyYearMonthTotal Sales
2Product 451210010762023-2-8520232864285 01 Jan02 Feb
3Product 461210010762023-1-41020231203333012100107612
4Product 461210010762023-2-1202023240666601210012581
5Product 511210012582023-2-20602023239142801210017921
6Product 511210012582023-2-243020232195714012100246222
7Product 511210017922023-1-413120231854617812100250711
8Product 511210017922023-1-9692023145014221210025351
9Product 511210019432023-1-4-5020231-326190012100273023
10Product 511210019432023-2-23502023232619001210027521
11Product 441210024622023-1-141020231100000012100303822
12Product 441210024622023-2-28202023220000001210033261
13Product 461210024622023-1-14102023120333301210033491
14Product 461210024622023-2-28202023240666601210033591
15Product 461210025072023-1-14202023140666601210034232
16Product 511210025072023-2-162020232130476012100373921
17Product 461210025352023-2-7420232813332
18Product 191210027302023-2-131020232985710
19Product 441210027302023-1-1020202312000000
20Product 441210027302023-1-2730202313000000
21Product 441210027302023-2-1330202323000000
22Product 441210027302023-2-2330202323000000
23Product 441210027302023-2-2820202322000000
24Product 461210027302023-1-1020202314066660
25Product 461210027302023-1-2730202316099990
26Product 461210027302023-1-3110202312033330
27Product 461210027302023-1-3110202312033330
28Product 461210027302023-2-1320202324066660
29Product 461210027302023-2-2320202324066660
30Product 461210027302023-2-2810202322033330
31Product 461210027522023-1-1410202312033330
32Product 441210030382023-1-520202312000000
33Product 441210030382023-2-2120202322000000
34Product 441210030382023-2-2420202322000000
35Product 461210030382023-1-525202315083325
36Product 461210030382023-1-2720202314066660
37Product 461210030382023-1-2810202312033330
38Product 461210030382023-2-2110202322033330
39Product 461210030382023-2-2420202324066660
40Product 441210033262023-1-1610202311000000
41Product 441210033262023-1-2730202313000000
42Product 511210033492023-2-1750202323261900
43Product 511210033592023-1-1641202312674758
44Product 441210034232023-1-1610202311000000
45Product 441210034232023-1-2720202312000000
46Product 461210034232023-1-1630202316099990
47Product 461210034232023-1-2730202316099990
48Product 441210037392023-1-9520231500000
49Product 441210037392023-2-15520232500000
50Product 461210037392023-1-9520231101666
51
52
Sheet1
Cell Formulas
RangeFormula
I2:K16I2=PIVOTBY(B2:B50,TEXT(C2:C50,"mm mmm"),A2:A50,LAMBDA(x,ROWS(UNIQUE(x))),,0,,0,,SUMIF(B:B,B2:B50,G:G)>0)
Dynamic array formulas.
 
Upvote 1
Not sure if this is what you're after:
I put your sample data into a spreadsheet A1:G50
I created a unique table of Customer codes via the unique function into I2
Excel Formula:
=UNIQUE(B2:B50)
Then copied the month's from the table to the heading, IE J1:K1 became 1 & 2
I then used a formula to count the number of sku's purchased by customer that month.
Excel Formula:
=COUNTIFS($B:$B,$I2,$F:$F,J$1,$D:$D,">0")
And encompassed the range you're wanting to detect.
In Q2 I added the Number of SKU's going from 1 down and used a formula in R2 going across the number of months (You might need to change the start column depending on the number of months in the previous table.
Excel Formula:
=COUNTIF(J$:J$,$Q2)
This returns the table that you requested. Hope that helps.
Hi Dermie,

Thank you so much, that's look promising, I have applied your approach and found how can I modify that if they buy same product, it will only count as 1? In the image below you can see this customer code 121002730 buy only 2 product even he/she bought in multiple times.
pic.JPG
 
Upvote 0
@blader1989
It would help you get better/faster replies if you could give your sample data in a form helpers can easily test with. :)
I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

Try a formula like this in J2 for the layout shown in post #3

Excel Formula:
=BYROW(I2:I4,LAMBDA(r,IFNA(ROWS(UNIQUE(FILTER(A2:A50,B2:B50=r,NA()))),0)))
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,928
Members
449,274
Latest member
mrcsbenson

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