Count And Sum Multiple Columns Grouped on Column

slipstream

Board Regular
Joined
Aug 24, 2005
Messages
70
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I've done a search on my problem and come up with many of different solutions but not quite what i need, things like Unique, V/H Stack, Groupby, Index, Match, Sumifs, Countifs, Lookups. TBH it's a little overwhelming I've not used Excel for a long time so bit out of the loop of the advancements.

Hopefully somebody can point me in the right direction.


I'm looking at producing a daily materials plan, data will change daily, however the fields are constant.
I have a Product which has a choice of colour inside, and outside
The inside and outside colours are interchangeable so I don't need to know if a colour is for the inside or outside just quantity per product, however the colours are exclusive to the Product

(I've tried installing XL2BB, however restrictions on the works network are preventing it installing)

From the attached table, the results expected would be :-

Prod1
White 5​
Blue 2​
Red 2​
Green 1​
Prod2
White 2​
Blue 1​
Green 1​
Prod3
Green 1​
White 3​


Hopefully, this makes sense, thanks for your time looking.

ProductIntColExtCol
Prod1WhiteWhite
Prod1WhiteGreen
Prod1BlueBlue
Prod1RedRed
Prod2WhiteBlue
Prod2WhiteGreen
Prod3GreenWhite
Prod3WhiteWhite
Prod1WhiteWhite
 

Attachments

  • Screenshot 2025-01-03 085504.png
    Screenshot 2025-01-03 085504.png
    13.8 KB · Views: 8

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
IF you have the relevant functions, would a layout like this be any use?

slipstream.xlsm
ABCDEFGHIJK
1ProductIntColExtCol BlueGreenRedWhiteTotal
2Prod1WhiteWhiteProd1212510
3Prod1WhiteGreenProd21124
4Prod1BlueBlueProd3134
5Prod1RedRedTotal3321018
6Prod2WhiteBlue
7Prod2WhiteGreen
8Prod3GreenWhite
9Prod3WhiteWhite
10Prod1WhiteWhite
11
Sheet1
Cell Formulas
RangeFormula
E1:J5E1=LET(p,Table1[Product],d,HSTACK(VSTACK(p,p),TOCOL(Table1[[IntCol]:[ExtCol]],,1)),c,TAKE(d,,-1),PIVOTBY(TAKE(d,,1),c,c,COUNTA))
Dynamic array formulas.
 
Upvote 0
Solution
Perfect, thank you for the quick response much appreciated.

I can work with that, just out of interest would it be easy enough if needed to switch the rows and columns on the results table, so colours down and products across.
 
Upvote 0
Sure, the easy way now would be to just add a TRANSPOSE to the current results

=LET(p,Table1[Product],d,HSTACK(VSTACK(p,p),TOCOL(Table1[[IntCol]:[ExtCol]],,1)),c,TAKE(d,,-1),TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)))

slipstream.xlsm
ABCDEFGHIJ
1ProductIntColExtCol Prod1Prod2Prod3Total
2Prod1WhiteWhiteBlue213
3Prod1WhiteGreenGreen1113
4Prod1BlueBlueRed22
5Prod1RedRedWhite52310
6Prod2WhiteBlueTotal104418
7Prod2WhiteGreen
8Prod3GreenWhite
9Prod3WhiteWhite
10Prod1WhiteWhite
11
Sheet1
Cell Formulas
RangeFormula
E1:I6E1=LET(p,Table1[Product],d,HSTACK(VSTACK(p,p),TOCOL(Table1[[IntCol]:[ExtCol]],,1)),c,TAKE(d,,-1),TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)))
Dynamic array formulas.
 
Upvote 0
If you want the original format:
Book1
ABCDEF
1ProductIntColExtColProd1
2Prod1WhiteWhiteWhite5
3Prod1WhiteGreenBlue2
4Prod1BlueBlueRed2
5Prod1RedRedGreen1
6Prod2WhiteBlueProd2
7Prod2WhiteGreenWhite2
8Prod3GreenWhiteBlue1
9Prod3WhiteWhiteGreen1
10Prod1WhiteWhiteProd3
11White3
12Green1
Sheet1
Cell Formulas
RangeFormula
E1:F12E1=IFNA(DROP(REDUCE("",UNIQUE(Table1[Product]),LAMBDA(x,y,VSTACK(x,y,LET(t,TOCOL(FILTER(Table1[[IntCol]:[ExtCol]],Table1[Product]=y)),GROUPBY(t,t,COUNTA,,0,-2))))),1),"")
Dynamic array formulas.
 
Upvote 0
A slightly different approach.
T202501a.xlsm
LMNOPQRST
1ProductIntColExtCol Prod1Prod2Prod3Total
2Prod1WhiteWhiteBlue213
3Prod1WhiteGreenGreen1113
4Prod1BlueBlueRed22
5Prod1RedRedWhite52310
6Prod2WhiteBlueTotal104418
7Prod2WhiteGreen
8Prod3GreenWhite
9Prod3WhiteWhite
10Prod1WhiteWhite
1c
Cell Formulas
RangeFormula
P1:T6P1=LET(a,VSTACK(L2:M10,HSTACK(L2:L10,N2:N10)),v,CHOOSECOLS(a,2),TRANSPOSE(PIVOTBY(CHOOSECOLS(a,1),v,v,COUNTA)))
Dynamic array formulas.
 
Upvote 0
Sorry I'm here again, i'm trying to add a filter to the below, I've added a new column to the table and want to filter depending on criteria.

I've created a filter on it's own and all works fine, =FILTER(Table1,Table1[Finish]="Smooth") however when implementing in to the main formula I'm getting an error.

Results
Prod1WhiteWhiteSmooth
Prod1RedRedSmooth
Prod2WhiteBlueSmooth
Prod2WhiteGreenSmooth
Prod1WhiteWhiteSmooth


New Table is :-


ProductIntColExtColFinish
Prod1WhiteWhiteSmooth
Prod1WhiteGreenTexture
Prod1BlueBlueTexture
Prod1RedRedSmooth
Prod2WhiteBlueSmooth
Prod2WhiteGreenSmooth
Prod3GreenWhiteTexture
Prod3WhiteWhiteTexture
Prod1WhiteWhiteSmooth


This is Peter's solution which works great.

=LET(p,Table1[Product],d,HSTACK(VSTACK(p,p),TOCOL(Table1[[IntCol]:[ExtCol]],,1)),c,TAKE(d,,-1),PIVOTBY(TAKE(d,,1),c,c,COUNTA))

I'm trying to filter on the Finish column ="Smooth" with this forumula

=LET(p,Table1[Product],filtered,FILTER(Table1,Table1[Finish]="Smooth"),d,HSTACK(VSTACK(p,p),TOCOL(filtered[[IntCol]:[ExtCol]],,1)),c,TAKE(d,,-1),TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)))



expected result:-
BlueGreenRedWhiteTotal
Prod1246
Prod21124
Total112610

however, i'm getting the below
1736155458682.png


1736155490357.png



Many thanks once again for your invaluable help.
 
Upvote 0
T202501a.xlsm
ABCDEFGHIJK
3ProductIntColExtColFinish BlueGreenRedWhiteTotal
4Prod1WhiteWhiteSmoothProd1246
5Prod1WhiteGreenTextureProd21124
6Prod1BlueBlueTextureTotal112610
7Prod1RedRedSmooth
8Prod2WhiteBlueSmooth
9Prod2WhiteGreenSmooth
10Prod3GreenWhiteTexture
11Prod3WhiteWhiteTexture
12Prod1WhiteWhiteSmooth
13
1cc
Cell Formulas
RangeFormula
F3:K6F3=LET(z,FILTER(A4:D12,D4:D12="Smooth"),a,VSTACK(HSTACK(CHOOSECOLS(z,1),CHOOSECOLS(z,2)),HSTACK(CHOOSECOLS(z,1),CHOOSECOLS(z,3))),v,CHOOSECOLS(a,2),PIVOTBY(CHOOSECOLS(a,1),v,v,COUNTA))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,225,400
Messages
6,184,762
Members
453,255
Latest member
excelbit

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