Summing an array of values based on multiple criteria and look up table - excel-formula

I am given the following sales table which provide the sales that each employee made, but instead of their name I have their ID and each ID may have more than 1 row.
To map the ID back to the name, I have a look up table with each employee's name and ID. One thing to keep in mind is that any given name could potentially have more than one ID assigned to it, as described in the example below:
Sales Table:
Year
ID
North
South
West
East
2020
A
58
30
74
72
2020
A
85
40
90
79
2020
B
9
82
20
5
2020
B
77
13
49
21
2020
C
85
55
37
11
2020
C
29
70
21
22
2021
A
61
37
21
42
2021
A
22
39
2
34
2021
B
62
55
9
72
2021
B
59
11
2
37
2021
C
41
22
64
47
2021
C
83
18
56
83
ID table:
ID
Name
A
Allison
B
Brandon
C
Brandon
I am trying to sum up each employee's sales by a given year, and aggregate all their transactions by their name (rather than ID), so that my result looks like the following:
Result:
Report
2021
Allison
258
Brandon
721
I want the user to be able to select the year, and the report would automatically sum up each person's sales by the year and their name. Again, Brandon was assigned ID B and C, so the report should be able to obtain all 2021 sales under B and C.
I posted a similar question which did not include the added complexity of having a name tied to more than one ID. In that thread, I was provided a solution with the following formula:
=SUMPRODUCT($C$2:$F$13*($B$2:$B$13=INDEX($I$2:$I$4,MATCH(N3,$J$2:$J$4,0)))*($A$2:$A$13=$N$2))
While this formula works on names that only have one ID tied to it, I believe the INDEX and MATCH component falls through once it encounters a duplicate name on the ID table.
I am currently using Excel 2016, so any solution would need to be compatible with that version at least. Thanks in advance for any guidance on this.

Try this formula solution can work in your Excel 2016
In L4, formula copied down :
=SUMPRODUCT(($A$3:$A$14=K$3)*(VLOOKUP(T(IF({1},$B$3:$B$14)),$H$3:$I$5,2,0)=K4)*$C$3:$F$14)

Related

Excel: How to Use AVERAGEIFS with Multiple Ranges (different columns)

Date
Group A
Group B
Group C
Group A
Sub Group
A1
B1
C1
A2
1/1/2022
35
12
54
10
1/2/2022
43
45
62
93
1/3/2022
76
65
39
48
1/4/2022
12
25
81
18
1/5/2022
89
76
20
26
1/6/2022
23
87
47
17
1/7/2022
56
59
21
53
1/8/2022
29
51
9
68
1/9/2022
76
8
52
35
1/10/2022
36
53
38
53
User Input
Start Dt - 1/1/2022
End Dt - 1/5/2022
Group - Group B
Question
What is the daily average of a Group given the above user input?
Formula
=AVERAGEIFS(INDEX($B$2:$E$11,,MATCH($I$3,$B$1:$E$1,0)), $A$2:$A$11, ">="&$G$3, $A$2:$A$11, "<="&$H$3)
Answer
44.6
User will select a start date, end date and Group.
I want to compute the daily average of that.
The issue arises when there are multiple columns with same group as Averageif takes the first column only.
Issue - How can I find the daily average of Group A for the given dates, given that Group A are in two columns (they can't be combined as there are multiple sub groups)
If you are on Microsoft-365 then can try-
=AVERAGE(FILTER(FILTER(B3:E12,B1:E1=I2),(A3:A12>=H1)*(A3:A12<=H2)))
If you have an older version you could use:
=AVERAGE(
INDEX(A1:E12,
AGGREGATE(15,6,ROW(A3:A12)/(A3:A12>=G3)/(A3:A12<=H3),
ROW(A1:INDEX(A:A,SUMPRODUCT((A3:A12>=G3)*(A3:A12<=H3))))),
AGGREGATE(15,6,COLUMN(B1:E1)/(B1:E1=I3),
TRANSPOSE(ROW(A1:INDEX(A:A,SUMPRODUCT(N(B1:E1=I3))))))))
Entered with ctrl+shift+enter (I think)
In the picture below J3 shows the answer cell. K3 is used to demonstrate the array that is used for the AVERAGE function (a Office 365 spill range).
Another old school approach. User input fields in the formula are referenced using named ranges.
=SUMPRODUCT(($A$3:$A$12>=StartDt)*($A$3:$A$12<=EndDt)
*($B1:$E$1=Group)*($B$3:$E$12))/(COUNTIFS($A$3:$A$12,">="&StartDt,$A$3:$A$12,"<="&EndDt)
*(COUNTIF($B$1:$E$1,Group)))

How can I delete duplicates group 3 columns using two criteria (first two columns)?

That is my data set enter code here
Year created Week created SUM_New SUM_Closed SUM_Open
0 2018 1 17 0 82
1 2018 6 62 47 18
2 2018 6 62 47 18
3 2018 6 62 47 18
4 2018 6 62 47 18
In last three columns there is already the sum for the year and week. I need to get rid of duplicates so that the table contains unique values (for the example above):
Year created Week created SUM_New SUM_Closed SUM_Open
0 2018 1 17 0 82
4 2018 6 62 47 18
I tried to group data but it somehow works wrong and does what I need but just for one column.
df.groupby(['Year created', 'Week created']).size()
And output:
Year created Week created
2017 48 2
49 25
50 54
51 36
52 1
2018 1 17
2 50
3 37
But it is just one column and I don't know which one because even if I separate the data on three parts and do the same procedure for each part I get the same result (as above) for all.
I believe need drop_duplicates:
df = df.drop_duplicates(['Year created', 'Week created'])
print (df)
Year created Week created SUM_New SUM_Closed SUM_Open
0 2018 1 17 0 82
1 2018 6 62 47 18
df2 = df.drop_duplicates(['Year created', 'Week created', 'SUM_New', 'SUM_Closed'])
print(df2)
hope this helps.

Find out minimum value of specific columns in a row in MS Excel

My table in Excel looks something like this:
abcd 67 94 52 89 24
efgh 23 45 93 54 34
ijkl 64 83 23 45 92
mnop 34 45 10 66 53
This is a student database containing marks obtained in various subjects. I need to calculate the percentage in each row such that out of 5 subjects, the first subject is always included with other 3 subject with maximum marks.
Example: abcd 67 94 52 89 24 75.5%
Here 75.5%=(67+94+52+89)/4=302/4=75.5 where 24 being the lowest has been excluded and 67 has to be taken even if it were the least.
What I require is the least(excluding the first column, of course) of all the columns in that particular row, so that I can sum all the marks and subtract this least marks and finally use it to calculate the percentage.
Any help/suggestion would be appreciated. Thank You.
You'll need to adjust this for your columns, but if you sum the entire range, then subtract the min value after, do a count of the range then subtract one from that, you will be able to get the average.
This code is using the 4 values from column B through F and the 4 values are: 67 94 52 89 24... which results in 75.5
=(SUM(B3:F3)-MIN(C3:F3))/(COUNT(B3:F3)-1)

SUMIFS/SUMPRODUCT for 2D data with multiple possible values in 2nd direction

I have been struggling with the following:
I have a data sheet as follows, from which I want to sum the amounts per week and groups of projects, where the group of projects is user input. This "data" sheet is schematically looking like this
A B C D E F G
1 YEAR 2017 2017 2017 2017 2017 2017
2 WEEK 40 41 42 43 44 45
3 ProjectA 100 101 102 104 100 85
4 ProjectB 80 80 85 82 80 82
5 ProjectC 60 60 60 60 60 60
6 ProjectD 105 108 112 116 120 122
Next step is that the question of which projects you'd need to sum, is user input, so in another sheet ("projects"), the user would input:
A
1 ProjectA
2 ProjectC
3
4
5
Then in the third sheet, I would have to show the summed data per week:
A B C D E F
1 2017 2017 2017 2017 2017 2017
2 40 41 42 43 44 45
3
Now the big question is, what formula could I use in row 3 of this last sheet?
What I have tried so far is: (in A3)
{=SUM(IF(data!B1:G1=A1;IF(data!B2:G2=A2;IF(data!A3:A6=projects!A1:A5;data!B3:G6))))}
This gives me a #N/A error. If I replace projects!A1:A5 by projects!A1, everything works fine, but then that's not much of a summation anymore :)
I have tried other versions with SUMIFS and SUMPRODUCT but those get me nowhere closer to where I'd like to be.
So, any help would be greatly appreciated.
(One last note, I am not able/allowed to change or add anything in the "data" sheet)
Use SUMPRODUCT:
=SUMPRODUCT((Data!$B$2:$G$2=A2)*(Data!$B$1:$G$1=A1)*(ISNUMBER(MATCH(Data!$A$3:$A$6,projects!$A:$A,0))),Data!$B$3:$G$6)

Excel indexmatch, vlookup

I have a holiday calendar for several years in one table. Can anyone help – How to arrange this data by week and show holiday against week? I want to reference this data in other worksheets and hence arranging this way will help me to use formulae on other sheets. I want the data to be: col A having week numbers and column B showing holiday for year 1, col. C showing holiday for year 2, etc.
Fiscal Week
2015 2014 2013 2012
Valentine's Day 2 2 2 3
President's Day 3 3 3 4
St. Patrick's Day 7 7 7 7
Easter 10 12 9 11
Mother's Day 15 15 15 16
Memorial Day 17 17 17 18
Flag Day 20 19 19 20
Father's Day 21 20 20 21
Independence Day 22 22 22 23
Labor Day 32 31 31 32
Columbus Day 37 37 37 37
Thanksgiving 43 43 43 43
Christmas 47 47 47 48
New Year's Day 48 48 48 49
ML King Day 51 51 51 52
It's not too clear what year 1 is, so I'm going to assume that's 2015, and year 2 is 2014, etc.
Here's how you could set it up, if I understand correctly. Use this index/match formula (psuedo-formula):
=Iferror(Index([holiday names range],match([week number],[2015's week numbers in your table],0)),"")
It looks like this:
(=IFERROR(INDEX($A$3:$A$17,MATCH($H3,B$3:B$17,0)),""), in the cell next to the week numbers)
You can then drag the formula over, and the matching group (in above picture, B3:B17) will "slide over" as you drag the formula over.

Resources