Summing the children...but only sometimes

teddy0bear

New Member
Joined
Aug 26, 2016
Messages
4
I'm trying to build a pivot table that will allow the user to select one department and it will show all say 3 data fields for that department. In some cases, however, the department they select will have sub departments. There is data at both the department level and the sub department level which is making things difficult. I have a department table that has a relationship already set up (*) with the data table.
My first issue is, if I do the filter on the department level (from the Dpt table) it wont show the sub departments in the filter. If I apply the filter to the Sub department level (Dpt table) it wont sum up the departments correctly. I'm not sure how to handle this?

To make my life more difficult, when the user selects ones of the parent departments, the pivot table needs to show the sum of 2 of the fields but not the last one. I think I have to tell it to ignore the relationship so it wont do that? I haven't figured that part out yet...

Dpt Table
*Sub Department / Department
Red / Red
Pink / Red
Magenta / Red
Blue / Blue
Turquoise / Blue

Data Table
*Department / Value1 / Value2 / Value3
Red / 1 / 4 / 2
Pink / 2 / 4 / 3
Magenta / 2 / 4 / 0

For example, if I were to say Pink I should get
2 / 4 / 3

If I were to say Red, I'm trying to get:
5 / 12 / 2
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,
Maybe something like:

Excel 2016 (Windows) 64 bit
ABCDEFGHIJKL
1subdeptdptv1v2v3v1v2v3
2redredred142red5125
3pinkredpink243
4magentaredmagenta240
5blueblue
6turquoiseblue
teddy0bear
Cell Formulas
RangeFormula
J2{=IF(COUNTIF(dpt,$I2)=1,INDEX(E$2:E$4,MATCH($I2,$D$2:$D$4,0)),SUM(SUMIF(teddy0bear!$D$2:$D$4,IF(teddy0bear!$B$2:$B$6=$I2,teddy0bear!$A$2:$A$6),INDEX(teddy0bear!E$2:E$4,MATCH($I2,teddy0bear!$D$2:$D$4,0),0))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
First range is a table called dpt.
That bit =IF(COUNTIF(dpt,$I2) here refers to range A2:B6
The formula is truncated somehow in the previous post:
CSE =IF(COUNTIF(dpt,$I2)=1,INDEX(E$2:E$4,MATCH($I2,$D$2:$D$4,0)),SUM(SUMIF(teddy0bear!$D$2:$D$4,IF(teddy0bear!$B$2:$B$6=$I2,teddy0bear!$A$2:$A$6),INDEX(teddy0bear!E$2:E$4,MATCH($I2,teddy0bear!$D$2:$D$4,0),0))))
 
Upvote 0
That sounds like something I would do if I was doing regular excel tables. The data table is coming from an external source and only exists as a connection in my data model. I could maybe add a calculated column into the dta model like this but I'd worry about adapting for changes on the dpt (as someone will decide that pink is blue, just you watch) and I still have the issue about it filtering properly when changing the slicer.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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