Averageifs

qarat

New Member
Joined
Apr 9, 2018
Messages
3
Hi everyone,

I have the following table

[TABLE="width: 425"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD="align: center"]Office[/TD]
[TD="align: center"]Position[/TD]
[TD="align: center"]Start Date[/TD]
[TD="align: center"]Termination Date[/TD]
[/TR]
[TR]
[TD="align: center"]New York[/TD]
[TD="align: center"]Manger[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]11-Nov-17[/TD]
[/TR]
[TR]
[TD="align: center"]Chicago[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]28-Dec-18[/TD]
[/TR]
[TR]
[TD="align: center"]Miami[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]13-Feb-17[/TD]
[/TR]
[TR]
[TD="align: center"]Boston[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]2-Apr-17[/TD]
[/TR]
[TR]
[TD="align: center"]Toronto[/TD]
[TD="align: center"]Manger[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]20-May-19[/TD]
[/TR]
[TR]
[TD="align: center"]Seattle[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]8-Jul-17[/TD]
[/TR]
[TR]
[TD="align: center"]Paris[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]26-Aug-19[/TD]
[/TR]
[TR]
[TD="align: center"]London[/TD]
[TD="align: center"]Manager[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]15-Oct-17[/TD]
[/TR]
[TR]
[TD="align: center"]Berlin[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]20-Jan-16[/TD]
[TD="align: center"]30-Sep-19[/TD]
[/TR]
[TR]
[TD="align: center"]Moscow[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]10-Sep-17[/TD]
[/TR]
[TR]
[TD="align: center"]Tokio[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]11-Aug-19[/TD]
[/TR]
[TR]
[TD="align: center"]Rome[/TD]
[TD="align: center"]Manager[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]14-May-17[/TD]
[/TR]
[TR]
[TD="align: center"]New York[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]6-Jul-19[/TD]
[/TR]
[TR]
[TD="align: center"]Chicago[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]28-Aug-17[/TD]
[/TR]
[TR]
[TD="align: center"]New York[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]21-Oct-19[/TD]
[/TR]
[TR]
[TD="align: center"]Boston[/TD]
[TD="align: center"]Manager[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]14-Dec-17[/TD]
[/TR]
[TR]
[TD="align: center"]Toronto[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]7-Feb-27[/TD]
[/TR]
[TR]
[TD="align: center"]Berlin[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]3-Apr-20[/TD]
[/TR]
[TR]
[TD="align: center"]Berlin[/TD]
[TD="align: center"]Manager[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]29-May-17[/TD]
[/TR]
[TR]
[TD="align: center"]Chicago[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]18-Jan-16[/TD]
[TD="align: center"]25-Jul-17[/TD]
[/TR]
</tbody>[/TABLE]



I urgently need to find average number of days all employees worked in the company by office and position using one formula and fill in the following table:

[TABLE="width: 396"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD="align: center"]Office[/TD]
[TD="align: center"]Manager[/TD]
[TD="align: center"]Senior Manager[/TD]
[TD="align: center"]Director[/TD]
[/TR]
[TR]
[TD="align: center"]New York[/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[/TR]
[TR]
[TD="align: center"]Boston[/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[/TR]
[TR]
[TD="align: center"]Berlin[/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[/TR]
[TR]
[TD="align: center"]Chicago
...[/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[TD="align: center"] [/TD]
[/TR]
</tbody>[/TABLE]

I think that AVERAGEIFS should be used but have no idea how to do this. Also some termination dates are later than today and this adds some complexity.
Please, help. Thanks a lot in advance.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I'd recommend a helper column to calulate the number of days per record. (This row can be hidden if needed)


Excel 2010
ABCDEFGHIJK
1OfficePositionStart DateTermination DateDaysOfficeManagerSenior ManagerDirector
2New YorkManger20-Jan-1611-Nov-17661Berlin497810812
3ChicagoDirector20-Jan-1628-Dec-18810Boston6960438
4MiamiSenior Manager20-Jan-1613-Feb-17390Chicago0588682
5BostonDirector20-Jan-162-Apr-17438London63400
6TorontoManger20-Jan-1620-May-19810Miami03900
7SeattleSenior Manager20-Jan-168-Jul-17535Moscow00601
8ParisDirector20-Jan-1626-Aug-19810New York08120
9LondonManager20-Jan-1615-Oct-17634Paris00810
10BerlinSenior Manager20-Jan-1630-Sep-19810Rome48200
11MoscowDirector18-Jan-1610-Sep-17601Seattle05350
12TokioDirector18-Jan-1611-Aug-19812Tokio00812
13RomeManager18-Jan-1614-May-17482Toronto00812
14New YorkSenior Manager18-Jan-166-Jul-19812
15ChicagoSenior Manager18-Jan-1628-Aug-17588
16New YorkSenior Manager18-Jan-1621-Oct-19812
17BostonManager18-Jan-1614-Dec-17696
18TorontoDirector18-Jan-167-Feb-27812
19BerlinDirector18-Jan-163-Apr-20812
20BerlinManager18-Jan-1629-May-17497
21ChicagoDirector18-Jan-1625-Jul-17554
Sheet1
Cell Formulas
RangeFormula
I2=IFERROR(AVERAGEIFS($E$2:$E$21,$A$2:$A$21,$H2,$B$2:$B$21,I$1),0)
J2=IFERROR(AVERAGEIFS($E$2:$E$21,$A$2:$A$21,$H2,$B$2:$B$21,J$1),0)
K2=IFERROR(AVERAGEIFS($E$2:$E$21,$A$2:$A$21,$H2,$B$2:$B$21,K$1),0)
E2=MIN(TODAY(),D2)-C2
 
Upvote 0
CalcSux78, thanks. It's an opportunity. But are there any variants without the helper column?
 
Upvote 0
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]Office[/TD]
[TD]Position[/TD]
[TD]Start Date[/TD]
[TD]Termination Date[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]New York[/TD]
[TD]Manager[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
11/11/2017​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]Chicago[/TD]
[TD]Director[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
12/28/2018​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]Miami[/TD]
[TD]Senior Manager[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
2/13/2017​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]Boston[/TD]
[TD]Director[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
4/2/2017​
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]Toronto[/TD]
[TD]Manager[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
5/20/2019​
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]Seattle[/TD]
[TD]Senior Manager[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
7/8/2017​
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]Paris[/TD]
[TD]Director[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
8/26/2019​
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]London[/TD]
[TD]Manager[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
10/15/2017​
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]Berlin[/TD]
[TD]Senior Manager[/TD]
[TD]
1/20/2016​
[/TD]
[TD]
9/30/2019​
[/TD]
[/TR]
[TR]
[TD]
11
[/TD]
[TD]Moscow[/TD]
[TD]Director[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
9/10/2017​
[/TD]
[/TR]
[TR]
[TD]
12
[/TD]
[TD]Tokio[/TD]
[TD]Director[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
8/11/2019​
[/TD]
[/TR]
[TR]
[TD]
13
[/TD]
[TD]Rome[/TD]
[TD]Manager[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
5/14/2017​
[/TD]
[/TR]
[TR]
[TD]
14
[/TD]
[TD]New York[/TD]
[TD]Senior Manager[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
7/6/2019​
[/TD]
[/TR]
[TR]
[TD]
15
[/TD]
[TD]Chicago[/TD]
[TD]Senior Manager[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
8/28/2017​
[/TD]
[/TR]
[TR]
[TD]
16
[/TD]
[TD]New York[/TD]
[TD]Senior Manager[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
10/21/2019​
[/TD]
[/TR]
[TR]
[TD]
17
[/TD]
[TD]Boston[/TD]
[TD]Manager[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
12/14/2017​
[/TD]
[/TR]
[TR]
[TD]
18
[/TD]
[TD]Toronto[/TD]
[TD]Director[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
2/7/2027​
[/TD]
[/TR]
[TR]
[TD]
19
[/TD]
[TD]Berlin[/TD]
[TD]Director[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
4/3/2020​
[/TD]
[/TR]
[TR]
[TD]
20
[/TD]
[TD]Berlin[/TD]
[TD]Manager[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
5/29/2017​
[/TD]
[/TR]
[TR]
[TD]
21
[/TD]
[TD]Chicago[/TD]
[TD]Director[/TD]
[TD]
1/18/2016​
[/TD]
[TD]
7/25/2017​
[/TD]
[/TR]
[TR]
[TD]
22
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
23
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
24
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
25
[/TD]
[TD]Office[/TD]
[TD]Manager[/TD]
[TD]Senior Manager[/TD]
[TD]Director[/TD]
[/TR]
[TR]
[TD]
26
[/TD]
[TD]New York[/TD]
[TD]
661​
[/TD]
[TD]
1318.5​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
27
[/TD]
[TD]Chicago[/TD]
[TD][/TD]
[TD]
588​
[/TD]
[TD]
813.5​
[/TD]
[/TR]
[TR]
[TD]
28
[/TD]
[TD]Miami[/TD]
[TD][/TD]
[TD]
390​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
29
[/TD]
[TD]Boston[/TD]
[TD]
696​
[/TD]
[TD][/TD]
[TD]
438​
[/TD]
[/TR]
[TR]
[TD]
30
[/TD]
[TD]Toronto[/TD]
[TD]
1216​
[/TD]
[TD][/TD]
[TD]
4038​
[/TD]
[/TR]
[TR]
[TD]
31
[/TD]
[TD]Seattle[/TD]
[TD][/TD]
[TD]
535​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
32
[/TD]
[TD]Paris[/TD]
[TD][/TD]
[TD][/TD]
[TD]
1314​
[/TD]
[/TR]
[TR]
[TD]
33
[/TD]
[TD]London[/TD]
[TD]
634​
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
34
[/TD]
[TD]Berlin[/TD]
[TD]
497​
[/TD]
[TD]
1349​
[/TD]
[TD]
1537​
[/TD]
[/TR]
[TR]
[TD]
35
[/TD]
[TD]Moscow[/TD]
[TD][/TD]
[TD][/TD]
[TD]
601​
[/TD]
[/TR]
[TR]
[TD]
36
[/TD]
[TD]Tokio[/TD]
[TD][/TD]
[TD][/TD]
[TD]
1301​
[/TD]
[/TR]
[TR]
[TD]
37
[/TD]
[TD]Rome[/TD]
[TD]
482​
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


B26=
IFERROR(AVERAGE(IF($A$2:$A$21=$A26,IF($B$2:$B$21=B$25,$D$2:$D$21-$C$2:$C$21))),"") control+shift+enter

Copy across and down
 
Upvote 0
MARZIOTULLIO , thanks a lot! But how to add the condition that if the termination date is in future, the number of days is calculated starting from today? For example the termination date for Director in Chicago is 28 December 2018. Therefore the number of days worked should be calculated from today 09 April 2018.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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