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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
There are probably many different approaches to your challenges.
N.B. We do not know the source of your data and we do not know what information you require from the data.
Can you organize the data to expedite preparing useful reports? Long complex formulas can be a challenge to maintain.
Experiment to find the best solutions for you.

T202501a.xlsm
ABCDEFGHIJK
1Count 2 columns
2Smooth
3ProductIntColExtColFinish BlueGreenRedWhiteTotal
4Prod1WhiteWhiteSmoothProd1246
5Prod1WhiteGreenTextureProd21124
6Prod1BlueBlueTextureTotal112610
7Prod1RedRedSmooth
8Prod2WhiteBlueSmoothTexture
9Prod2WhiteGreenSmooth BlueGreenWhiteTotal
10Prod3GreenWhiteTextureProd12114
11Prod3WhiteWhiteTextureProd3134
12Prod1WhiteWhiteSmoothTotal2248
13
14
15IntColExtCol Smooth|Prod1Smooth|Prod2Texture|Prod1Texture|Prod3Total
16Smooth|Prod1WhiteWhiteBlue123
17Texture|Prod1WhiteGreenGreen1113
18Texture|Prod1BlueBlueRed22
19Smooth|Prod1RedRedWhite421310
20Smooth|Prod2WhiteBlueTotal644418
21Smooth|Prod2WhiteGreen
22Texture|Prod3GreenWhite
23Texture|Prod3WhiteWhite
24Smooth|Prod1WhiteWhite
25
26
1cc
Cell Formulas
RangeFormula
F3:K6F3=LET(z,FILTER(A4:D12,D4:D12=F2),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))
F9:J12F9=LET(z,FILTER(A4:D12,D4:D12=F8),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))
E15:J20E15=LET(a,VSTACK(A16:B24,HSTACK(A16:A24,C16:C24)),v,CHOOSECOLS(a,2),TRANSPOSE(PIVOTBY(CHOOSECOLS(a,1),v,v,COUNTA)))
A16:A24A16=D4&"|"&A4
B16:C24B16=B4
Dynamic array formulas.
 
Upvote 0
I've got a source table setup on a worksheet, which will be populated daily with new data, the source data from an external source is formatted for a straight copy and paste.
Then on another worksheet, 2 formatted results tables (=Smooth and =Texture) based on your formula which can be printed giving all the info we need.

It's pretty basic info we need out just wasn't sure on how to group and collate it together, the data format coming in will likely remain constant for sometime so no real need for anything more complex at this point.

It's a little frustrating that I've only got office 2021 at home so can't play around with many of the new functions, just need to find a few spare hours at work to sit down and take a deeper dive.

Many thanks @Dave Patton and the rest of you for spending the time on this for me and giving me a few different avenues to investigate further, much appreciated.
 
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.
If you want to keep the table nomenclature (so that the formula automatically adjusts to any increase/decrease in number of data rows) & similar result layout as before ..

slipstream.xlsm
ABCDEFGHIJK
1ProductIntColExtColFinishFinish Filter Prod1Prod2Total
2Prod1WhiteWhiteSmoothSmoothBlue11
3Prod1WhiteGreenTextureGreen11
4Prod1BlueBlueTextureRed22
5Prod1RedRedSmoothWhite426
6Prod2WhiteBlueSmoothTotal6410
7Prod2WhiteGreenSmooth
8Prod3GreenWhiteTexture
9Prod3WhiteWhiteTexture
10Prod1WhiteWhiteSmooth
11
12
Sheet1
Cell Formulas
RangeFormula
H1:K6H1=LET(f,DROP(FILTER(Table1,Table1[Finish]=F2),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)))
Dynamic array formulas.
 
Upvote 0
Two other options if you maybe didn't want that separate filter value cell I have in F2 - but did want the results to reflect what that filter option was ..

1. Put that filter option out of sight, maybe even on another sheet (though I have just put it in column L to demonstrate)

slipstream.xlsm
ABCDEFGHIJKL
1ProductIntColExtColFinishSmoothProd1Prod2TotalFinish Filter
2Prod1WhiteWhiteSmoothBlue11Smooth
3Prod1WhiteGreenTextureGreen11
4Prod1BlueBlueTextureRed22
5Prod1RedRedSmoothWhite426
6Prod2WhiteBlueSmoothTotal6410
7Prod2WhiteGreenSmooth
8Prod3GreenWhiteTexture
9Prod3WhiteWhiteTexture
10Prod1WhiteWhiteSmooth
11
Sheet1
Cell Formulas
RangeFormula
F1:I6F1=LET(f,DROP(FILTER(Table1,Table1[Finish]=L2),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),a,TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)),MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IF(AND(r=1,c=1),L2,INDEX(a,r,c)))))
Dynamic array formulas.



2. Put the filter value in the formula itself but also have it show in the results.

slipstream.xlsm
ABCDEFGHI
1ProductIntColExtColFinishSmoothProd1Prod2Total
2Prod1WhiteWhiteSmoothBlue11
3Prod1WhiteGreenTextureGreen11
4Prod1BlueBlueTextureRed22
5Prod1RedRedSmoothWhite426
6Prod2WhiteBlueSmoothTotal6410
7Prod2WhiteGreenSmooth
8Prod3GreenWhiteTexture
9Prod3WhiteWhiteTexture
10Prod1WhiteWhiteSmooth
11
Sheet1
Cell Formulas
RangeFormula
F1:I6F1=LET(flt,"Smooth",f,DROP(FILTER(Table1,Table1[Finish]=flt),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),a,TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)),MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IF(AND(r=1,c=1),flt,INDEX(a,r,c)))))
Dynamic array formulas.
 
Upvote 0
Sorry, yet another thought ..
on another worksheet, 2 formatted results tables (=Smooth and =Texture)
Will the data always have both Finishes or might you need modification along these lines in case not?

slipstream.xlsm
ABCDEFG
1ProductIntColExtColFinishNo Smooth
2Prod1WhiteWhiteTexture
3Prod1WhiteGreenTexture
4Prod1BlueBlueTexture
5Prod1RedRedTexture
6Prod2WhiteBlueTexture
7Prod2WhiteGreenTexture
8Prod3GreenWhiteTexture
9Prod3WhiteWhiteTexture
10Prod1WhiteWhiteTexture
11
Sheet1
Cell Formulas
RangeFormula
F1F1=LET(flt,"Smooth",f,DROP(FILTER(Table1,Table1[Finish]=flt,NA()),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),a,TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)),IFNA(MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IF(AND(r=1,c=1),flt,INDEX(a,r,c)))),"No "&flt))
 
Upvote 0
@Peter_SSs currently it's just the 2 options, either 1 or the other, smooth or texture, later down the line there may be additional, but just the 2 for now.
 
Upvote 0
@Peter_SSs currently it's just the 2 options, either 1 or the other, smooth or texture, later down the line there may be additional, but just the 2 for now.
I think that you may have misinterpreted what I was saying. I didn't mention anything about more then 2 options did I?
 
Upvote 0
Apologies @Peter_SSs , if you're meaning from the source data, then there would always be products with a Smooth Finish, some days would be both and some days there may not be any Texture at all.
 
Upvote 0
some days there may not be any Texture at all.
That is what I was getting at. You has said ..
Then on another worksheet, 2 formatted results tables (=Smooth and =Texture) based on your formula which can be printed
.. and I presumed that if there was no rows with one of Smooth or Texture then you would probably not want #CALC! printed out but either nothing at all for that table or a message indicating no results.
In the mini sheet below cell F5 has a formula from an earlier post of mine and most, if not all, the previous suggestions would produce such an error if no results exist. The modified formula from post 16 in cell F1 I thought might be better if printed. .. or perhaps you would want nothing at all like in cell F3?

slipstream.xlsm
ABCDEF
1ProductIntColExtColFinishNo Texture
2Prod1WhiteWhiteSmooth
3Prod1WhiteGreenSmooth 
4Prod1BlueBlueSmooth
5Prod1RedRedSmooth#CALC!
6Prod2WhiteBlueSmooth
7Prod2WhiteGreenSmooth
8Prod3GreenWhiteSmooth
9Prod3WhiteWhiteSmooth
10Prod1WhiteWhiteSmooth
11
Sheet1
Cell Formulas
RangeFormula
F1F1=LET(flt,"Texture",f,DROP(FILTER(Table1,Table1[Finish]=flt,NA()),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),a,TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)),IFNA(MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IF(AND(r=1,c=1),flt,INDEX(a,r,c)))),"No "&flt))
F3F3=LET(flt,"Texture",f,DROP(FILTER(Table1,Table1[Finish]=flt,NA()),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),a,TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)),IFNA(MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IF(AND(r=1,c=1),flt,INDEX(a,r,c)))),""))
F5F5=LET(flt,"Texture",f,DROP(FILTER(Table1,Table1[Finish]=flt),,-1),p,TAKE(f,,1),d,HSTACK(VSTACK(p,p),TOCOL(DROP(f,,1),,1)),c,TAKE(d,,-1),a,TRANSPOSE(PIVOTBY(TAKE(d,,1),c,c,COUNTA)),MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IF(AND(r=1,c=1),flt,INDEX(a,r,c)))))
 
Upvote 0

Forum statistics

Threads
1,225,400
Messages
6,184,761
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