Swiftslide
New Member
- Joined
- May 28, 2012
- Messages
- 8
I have a mapping of persons to groups, in the form:
On another sheet, I have a table of Names to hours worked, by month, in the form
Say I want to add up the total hours of worked of all people in group 3 over the six months. If I were to add another column to the dates table, I could insert the group numbers into that column and then use the formula:
Alternatively, I could use the following formula, hardcoding the names of group 3 members into it:
However, I would rather use relational references. I.e. I want a formula that looks up the first table to find which Names are in group 3, then performs the sumproduct (or some equivalent function to get the total hours). Is this possible?
Code:
<table border="0" cellpadding="0" cellspacing="0" width="128"><colgroup><col style="width:48pt" span="2" width="64"> </colgroup><tbody><tr style="height:12.75pt" height="17"><td class="xl65" style="height:12.75pt;width:48pt" height="17" width="64">Person</td><td class="xl65" style="width:48pt" width="64">Group</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Ben</td><td class="xl66" align="right">1</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Sarah</td><td align="right">1</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Jack</td><td align="right">3</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Alice</td><td align="right">4</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Jason</td><td align="right">7</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Andrew</td><td align="right">2</td></tr><tr style="height:12.75pt" height="17"><td class="xl66" style="height:12.75pt" height="17">Jessica</td><td align="right">3</td></tr> </tbody></table>
Code:
<table border="0" cellpadding="0" cellspacing="0" width="448"><colgroup><col style="width:48pt" span="7" width="64"> </colgroup><tbody><tr style="height:12.75pt" height="17"><td class="xl67" style="height:12.75pt;width:48pt" height="17" width="64">Person</td><td class="xl67" style="width:48pt" width="64">January</td><td class="xl67" style="width:48pt" width="64">February</td><td class="xl67" style="width:48pt" width="64">March</td><td class="xl67" style="width:48pt" width="64">April</td><td class="xl67" style="width:48pt" width="64">May</td><td class="xl67" style="width:48pt" width="64">June</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Ben</td><td align="right">98</td><td align="right">56</td><td align="right">32</td><td align="right">3</td><td align="right">98</td><td align="right">32</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Sarah</td><td align="right">100</td><td align="right">8</td><td align="right">111</td><td align="right">3</td><td align="right">109</td><td align="right">99</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Jack</td><td align="right">112</td><td align="right">9</td><td align="right">9</td><td align="right">12</td><td align="right">90</td><td align="right">98</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Alice</td><td align="right">47</td><td align="right">89</td><td align="right">1</td><td align="right">0</td><td align="right">83</td><td align="right">8</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Jason</td><td align="right">38</td><td align="right">78</td><td align="right">33</td><td align="right">11</td><td align="right">44</td><td align="right">9</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Andrew</td><td align="right">12</td><td align="right">33</td><td align="right">130</td><td align="right">131</td><td align="right">24</td><td align="right">14</td></tr><tr style="height:12.75pt" height="17"><td class="xl68" style="height:12.75pt" height="17">Jessica</td><td align="right">78</td><td align="right">78</td><td align="right">22</td><td align="right">77</td><td align="right">23</td><td align="right">44</td></tr> </tbody></table>
Code:
=SUMPRODUCT(($B$2:$B$8 = 3) * $C$2:$H$8)
Code:
=SUMPRODUCT((($B$2:$B$8 = "Jack") + ($B$2:$B$8 = "Jessica")) * $C$2:$H$8)