Combine Filter and Aggregate Function?

jakeman

Active Member
Joined
Apr 29, 2008
Messages
325
Office Version
  1. 365
Platform
  1. Windows
Is it possible to combine the Filter function with the Aggregate Function?

I have a table that spans several columns but I am interested in only two of them: Goal and % Completed. The Goal column has multiple rows that I want to Average the % Completed for. In the image attachment, my desired output would only show 6 rows with an average.

I've managed to get the first part shown in the attached image but I cannot figure the Aggregate function:

Excel Formula:
=FILTER(UNIQUE(FILTER(Plan_Tbl,(Plan_Tbl[#Headers]="Process / Function")+(Plan_Tbl[#Headers]="Goal")+(Plan_Tbl[#Headers]="Goal CP%"))),{1,0,1})

Would anyone be able to assist?
 

Attachments

  • Screenshot 2023-06-01 121933.png
    Screenshot 2023-06-01 121933.png
    9 KB · Views: 28

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
How about
Excel Formula:
=LET(u,UNIQUE(Plan_Tbl[Process / Function]),HSTACK(u,AVERAGEIFS(Plan_Tbl[Goal CP%],Plan_Tbl[Process / Function],u)))
 
Upvote 0
Hey, Fluff - thank you for this solution. I'm nearly there.

However, the approach you gave me is just not quite there. The way you've arranged the formula causes the Average to take additional Goals into the calculation that I do not want. I want a distinct list of Process / Function, Goal, and Goal CP% first, and then an Average of the Process / Function once that happens.

Basically, the UNIQUE was supposed to take the below table:

Process / FunctionGoalGoal CP %
Product 1Task 1100%
Product 1Task 1100%
Product 1Task 245%

and convert it to this:

Process / FunctionGoalGoal CP%
Product 1Task 1100%
Product 1Task 245%

The formula you provided to me would yield an average of (100+100+45)/3 = 81.66 but what I'm looking for is actually (100+45)/2 = 72.5.

I really do appreciate your initial work on this. I have never used the LET function before and I'm trying to understand it and the HSTACK.
 
Upvote 0
Considering your image did not show the Goal column & your formula filtered it out, I didn't think it was important.
How about
Excel Formula:
=LET(u,UNIQUE(Plan_Tbl[[Process / Function]:[Goal]]),HSTACK(u,AVERAGEIFS(Plan_Tbl[Goal CP%],Plan_Tbl[Process / Function],INDEX(u,,1),Plan_Tbl[Goal],INDEX(u,,2))))
 
Upvote 0
Sorry, Fluff - I led you down the wrong path. Apologies for my lack of clarity. Let me start back from the beginning. Your solution is so close, I know it.

The the table on the right in the attached image is what I'm after. The problem is that I cannot get the right number of records to be Averaged in the formula you've provided to me previously, because there are some non-unique records being Averaged which are throwing my numbers off.

The below formula gets me the correct unique records that I need to Average but I cannot figure out how to Average this created array. I'm afraid if I go back to the original array and try to perform an Average on it, my results will continue to be skewed. That being said, is it possible to use the below formula as is and add in the AVERAGE IF and HSTACK functions around it?

Excel Formula:
=FILTER(UNIQUE(FILTER(Plan_Tbl,(Plan_Tbl[#Headers]="Process / Function")+(Plan_Tbl[#Headers]="Goal")+(Plan_Tbl[#Headers]="Goal CP%"))),{1,0,1})
 

Attachments

  • Screenshot 2023-06-01 121933.png
    Screenshot 2023-06-01 121933.png
    9 KB · Views: 7
Upvote 0
Can you please post some sample data using the XL2BB add-in & explain clearly what you are after.
 
Upvote 0
Sample Data.xlsx
ABCDEFGHI
1IDProcess / FunctionGoalTaskTask %CPGoal %CPProcess / FunctionAve Goal %CP
21Product 1Data MigrationTask 133%46%Product 146%
32Product 1Data MigrationTask 225%46%Product 265%
43Product 1Data MigrationTask 350%46%
54Product 1Data MigrationTask 475%46%
65Product 2Training & DevelopmentTask 1100%100%
76Product 2Training & DevelopmentTask 2100%100%
87Product 2Training & DevelopmentTask 3100%100%
98Product 2Training & DevelopmentTask 4100%100%
109Product 2Curriculum DevelopmentTask 130%30%
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Sheet1
 
Upvote 0
So you only want to average the Task1 for each product, is that correct?
 
Upvote 0
The above table represents the results I'm looking to achieve. I want to average the unique value for Goal.
So in the case of Product 2, there are two unique Goal values (Training & Development and Curriculum Development). If I average all of the Goal %CP I will get an inflated number (100*4 + 30)=86% but I really want to take the average of the unique Goal values for each Process/Function which would be (100+30)=65%
 
Upvote 0
Ok, how about
Excel Formula:
=LET(u,UNIQUE(Plan_Tbl[Process / Function]),d,CHOOSECOLS(UNIQUE(FILTER(Plan_Tbl,(Plan_Tbl[#Headers]="Process / Function")+(Plan_Tbl[#Headers]="Goal")+(Plan_Tbl[#Headers]="Goal %CP"))),1,3),HSTACK(u,BYROW(u,LAMBDA(br,AVERAGE(FILTER(INDEX(d,,2),INDEX(d,,1)=br))))))
 
Upvote 1
Solution

Forum statistics

Threads
1,215,086
Messages
6,123,043
Members
449,092
Latest member
ikke

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