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: 11

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
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
@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)))
Hi Peter,

Thank you so much. I have tried your code by it didn't show anything so I copy with XL2BB for you to check

Book1.xlsx
ABCDEFGHIJ
1Product NameCustomer CodeBilling DateQtyYearMonthTotal SalesJan
2Product 4412100246214/01/2023102023110000001210024622
3Product 4412100273010/01/202320202312000000121002730#SPILL!
4Product 4412100273027/01/2023302023130000001210030381
5Product 4412100303805/01/2023202023120000001210010761
6Product 4612100107604/01/2023102023120333301210025071
7Product 4612100246214/01/2023102023120333301210027521
8Product 4612100250714/01/2023202023140666601210017922
9Product 4612100273010/01/2023202023140666601210019430
10Product 4612100273027/01/202330202316099990
11Product 4612100273031/01/202310202312033330
12Product 4612100273031/01/202310202312033330
13Product 4612100275214/01/202310202312033330
14Product 5112100179204/01/2023131202318546178
15Product 5112100179209/01/202369202314501422
16Product 5112100194304/01/2023-5020231-3261900
Sheet2
Cell Formulas
RangeFormula
I2:I9I2=UNIQUE(B2:B16)
J2,J4:J9J2=COUNTIFS($B:$B,$I2,$G:$G,">0")
J3J3=BYROW(I2:I9,LAMBDA(r,IFNA(ROWS(UNIQUE(FILTER(A2:A16,B2:B16=r,NA()))),0)))
Dynamic array formulas.
 
Upvote 0
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
Hi @dermie_72 and @Peter_SSs

Thank you so much for your help, it nearly solved my problem at 99%, only 1% at how can we include the condition that the total value of purchased product should be large than 0 in post# 2 (=COUNTIFS($B:$B,$I2,$F:$F,J$1,$D:$D,">0"))? Because in our scenario, when customer returned the product, it will show the negative in the report. Like the table below, the customer code 121002730 when counting purchased product should be 1 because the product 44 purchased by he/she was 0 -> means the product was return due to any reason.

Book1_SKU purchased segment.xlsx
ABCDEFGHIJK
1Product NameCustomer CodeBilling DateQtyYearMonthTotal SalesJan
2Product 4412100246214/01/2023102023110000001210024622
3Product 4412100273010/01/2023202023120000001210027302should be 1
4Product 4412100273011/01/2023-2020231-20000001210030381
5Product 4412100303805/01/2023202023120000001210010761
6Product 4612100107604/01/2023102023120333301210025071
7Product 4612100246214/01/2023102023120333301210027521
8Product 4612100250714/01/2023202023140666601210017921
9Product 4612100273010/01/2023202023140666601210019431
10Product 4612100273027/01/202330202316099990
11Product 4612100273031/01/202310202312033330
12Product 4612100273031/01/202310202312033330
13Product 4612100275214/01/202310202312033330
14Product 5112100179204/01/2023131202318546178
15Product 5112100179209/01/202369202314501422
16Product 5112100194304/01/2023-5020231-3261900
Sheet2
Cell Formulas
RangeFormula
I2:I9I2=UNIQUE(B2:B16)
J2:J9J2=BYROW(I2#,LAMBDA(r,IFNA(ROWS(UNIQUE(FILTER(A2:A16,B2:B16=r,NA()))),0)))
Dynamic array formulas.
 

Attachments

  • Capture.JPG
    Capture.JPG
    227.2 KB · Views: 7
Upvote 0
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

Forum statistics

Threads
1,224,823
Messages
6,181,177
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