Sumifs for rows and columns that are in an interval - excel

I am trying to write a formula in excel that will take values from a table based on few criterias. Table looks like this:
+------------+----+----+----+-----+----+----+----+----+
| Month/Hour | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
+------------+----+----+----+-----+----+----+----+----+
| 1 | 93 | 21 | 32 | 42 | 55 | 30 | 98 | 97 |
| 2 | 41 | 73 | 25 | 58 | 48 | 10 | 19 | 20 |
| 3 | 87 | 17 | 92 | 100 | 9 | 31 | 22 | 22 |
| 4 | 92 | 91 | 63 | 28 | 95 | 58 | 55 | 47 |
| 5 | 56 | 34 | 69 | 60 | 87 | 64 | 40 | 53 |
| 6 | 8 | 64 | 92 | 30 | 48 | 27 | 52 | 65 |
| 7 | 77 | 6 | 27 | 45 | 29 | 91 | 24 | 90 |
| 8 | 13 | 14 | 31 | 10 | 40 | 49 | 22 | 57 |
| 9 | 70 | 16 | 55 | 95 | 85 | 41 | 65 | 17 |
| 10 | 72 | 79 | 81 | 48 | 13 | 40 | 99 | 52 |
| 11 | 76 | 88 | 80 | 45 | 97 | 68 | 64 | 62 |
| 12 | 73 | 82 | 97 | 74 | 93 | 7 | 6 | 71 |
+------------+----+----+----+-----+----+----+----+----+
In the first column we have months (1 - January, 2 - February, etc.) In the first row we have hours from 1 to 8.
Now I need a formula that for months <3,8> would sum values from hours <2,6> and for the rest of months (1-2, 9-12) would sum values from hours <4,7>. I've tried using Sumifs formula but it seems like it works only for one column at a time.
If it is not viable to use formula then I have some VBA knowledge and such solution would be welcome too.

Assuming months are in A2:A13 and the hours in B1:I1 you can use this formula
=SUMPRODUCT(ISNUMBER(MATCH(A2:A13,{3,8},0)*MATCH(B1:I1,{2,6},0))+0,B2:I13)
Vary as required for any combination of months/hours

list your months and hours then use MATCH inside an SUMPRODUCT:
=SUMPRODUCT(B2:I13,ISNUMBER(MATCH(B1:I1,M:M,0))*ISNUMBER(MATCH(A2:A13,L:L,0)))
Neither the Months nor the Hours desired needs to be consecutive.

Related

look up the average value based on 2 categories and calculate

enter image description here
I have data that will look up the average results of rows that fit the "X" category with the prefix of "id" with a data table like this
data
--------------------------
X | id | value
--------------------------
Mos | 1.1. | 74 | 78 | 70
Mos | 1.2. | 70 | 79 | 70
Mos | 2.1 | 70 | 76 | 73
Mos | 2.2 | 70 | 73 | 75
Mos | 3.1 | 77 | 72 | 78
Abs | 3.1 | 75 | 76 | 79
Abs | 3.2 | 74 | 80 | 77
Abs | 4.1 | 71 | 78 | 77
Abs | 4.2 | 76 | 76 | 76
Abs | 4.3 | 71 | 73 | 72
Cor | 1.2. | 75 | 70 | 78
Cor | 1.3. | 78 | 79 | 80
Cor | 2.1 | 79 | 70 | 70
Cor | 3.3 | 78 | 79 | 80
Cor | 4.1 | 78 | 74 | 72
Cor | 4.2 | 78 | 72 | 78
--------------------------
and the results as follows
result
------------------------
id | Mos | Abs | Cor
------------------------
1 | 73.5 | 0.0 | 76.7
2 | 72.8 | 0.0 | 73.0
3 | 75.7 | 76.8 | 79.0
4 | 0.0 | 74.4 | 75.3
how to make the formula?
Asume like this:
=IF("MOS" and LEFT(,1),SUM(D3:F4)/COUNT(D3:F4))
if you find "MOS" in the "X" column, according to the "id" that starts with (1 or 2 or 3 or 4), then the value table will add up and divide.
or
=AVERAGEIFS(D3:F18,B3:F18,I2,C3:F18,H3&"*")
Using a sample of your data, put this in H3 and copy down and across as necessary. An array formula so use Ctrl+Shift+Enter.
=AVERAGE(IF($A$2:$A$8=H$2,IF(VALUE(LEFT($B$2:$B$8,1))=$G3,$C$2:$E$8)))

How can I create a time variable with Stata or Excel?

I have a dataset that I am editing so it can be used for a time series regression since the time is not currently in a format that is usable. The format of the existing data is as follows:
--------------------------------------------------
| id|size |2017price|2016price|2015price|2014price| ...
-------------------------------------------------
| 1 | 3 | 50 | 80 | 21 | 56 | ...
--------------------------------------------------
| 2 | 5 | 78 | 85 | 54 | 67 | ...
--------------------------------------------------
| 3 | 2 | 18 | 22 | 34 | 54 | ...
--------------------------------------------------
...
...
...
I would like to add a time variable that accounts for each year and gives the corresponding value as a price variable;
---------------------------
| id | size |t | price|
--------------------------
| 1 | 3 |2017| 50 |
--------------------------
| 1 | 3 |2016| 80 |
--------------------------
| 1 | 3 |2015| 21 |
--------------------------
| 1 | 3 |2014| 21 |
--------------------------
| 2 | 5 |2017| 78 |
--------------------------
| 2 | 5 |2016| 85 |
--------------------------
| 2 | 5 |2015| 54 |
--------------------------
| 2 | 5 |2014| 67 |
--------------------------
| 3 | 2 |2017| 18 |
--------------------------
| 3 | 2 |2016| 22 |
--------------------------
| 3 | 2 |2015| 34 |
--------------------------
| 3 | 2 |2014| 54 |
--------------------------
...
...
...
Is there a function in Stata or Excel that can do this automatically? I have data for 20 years with over 35,000 entries so manually editing won't work.
Your data example as given is not quite suitable as Stata data as variable names cannot begin with numeric characters.
That fixed, this is an exercise for the reshape command (not function).
clear
input id size price2017 price2016 price2015 price2014
1 3 50 80 21 56
2 5 78 85 54 67
3 2 18 22 34 54
end
reshape long price, i(id size) j(year)
sort id size year
list , sepby(id)
+--------------------------+
| id size year price |
|--------------------------|
1. | 1 3 2014 56 |
2. | 1 3 2015 21 |
3. | 1 3 2016 80 |
4. | 1 3 2017 50 |
|--------------------------|
5. | 2 5 2014 67 |
6. | 2 5 2015 54 |
7. | 2 5 2016 85 |
8. | 2 5 2017 78 |
|--------------------------|
9. | 3 2 2014 54 |
10. | 3 2 2015 34 |
11. | 3 2 2016 22 |
12. | 3 2 2017 18 |
+--------------------------+

excel I need formula in column name "FEBRUARY"

I have a set of data as below.
SHEET 1
+------+-------+
| JANUARY |
+------+-------+
+----+----------+------+-------+
| ID | NAME |COUNT | PRICE |
+----+----------+------+-------+
| 1 | ALFRED | 11 | 150 |
| 2 | ARIS | 22 | 120 |
| 3 | JOHN | 33 | 170 |
| 4 | CHRIS | 22 | 190 |
| 5 | JOE | 55 | 120 |
| 6 | ACE | 11 | 200 |
+----+----------+------+-------+
SHEET2
+----+----------+------+-------+
| ID | NAME |COUNT | PRICE |
+----+----------+------+-------+
| 1 | CHRIS | 13 | 123 |
| 2 | ACE | 26 | 165 |
| 3 | JOE | 39 | 178 |
| 4 | ALFRED | 21 | 198 |
| 5 | JOHN | 58 | 112 |
| 6 | ARIS | 11 | 200 |
+----+----------+------+-------+
The RESULT should look like this in sheet1 :
+------+-------++------+-------+
| JANUARY | FEBRUARY |
+------+-------++------+-------+
+----+----------+------+-------++-------+-------+
| ID | NAME |COUNT | PRICE || COUNT | PRICE |
+----+----------+------+-------++-------+-------+
| 1 | ALFRED | 11 | 150 || 21 | 198 |
| 2 | ARIS | 22 | 120 || 11 | 200 |
| 3 | JOHN | 33 | 170 || 58 | 112 |
| 4 | CHRIS | 22 | 190 || 13 | 123 |
| 5 | JOE | 55 | 120 || 39 | 178 |
| 6 | ACE | 11 | 200 || 26 | 165 |
+----+----------+------+-------++-------+-------+
I need formula in column name "FEBRUARY". this formula will find its match in sheet 2
Assuming the first Count value should go in cell E3 of Sheet1, the following formula would be the usual way of doing it:-
=INDEX(Sheet2!C:C,MATCH($B3,Sheet2!$B:$B,0))
Then the Price (in F3) would be given by
=INDEX(Sheet2!D:D,MATCH($B3,Sheet2!$B:$B,0))
I think this query will work fine for your requirement
SELECT `Sheet1$`.ID,`Sheet1$`.NAME, `Sheet1$`.COUNT AS 'Jan-COUNT',`Sheet1$`.PRICE AS 'Jan-PRICE', `Sheet2$`.COUNT AS 'Feb-COUNT',`Sheet2$`.PRICE AS 'Feb-PRICE'
FROM `C:\Users\Nagendra\Desktop\aaaaa.xlsx`.`Sheet1$` `Sheet1$`, `C:\Users\Nagendra\Desktop\aaaaa.xlsx`.`Sheet2$` `Sheet2$`
WHERE (`Sheet1$`.NAME=`Sheet2$`.NAME)
Provide Actual path insted of
C:\Users\Nagendra\Desktop\aaaaa.xlsx
First you need to know about how to make connection. So refer http://smallbusiness.chron.com/use-sql-statements-ms-excel-41193.html

Top 5 Results per Subject

I have a list of exam subjects, student numbers and the score of each student per subject. What I'm trying to do is identify the top 4 scoring students per subject.
An example of the data that I have currently:
+--------------------+-------------+------------+
| Subject | Student ID | Test Score |
+--------------------+-------------+------------+
| Maths 1 | Student 001 | 78 |
| Maths 2 | Student 001 | 63 |
| English Lang | Student 001 | 64 |
| English Lit | Student 001 | 88 |
| Chemistry | Student 001 | 89 |
| Biology | Student 001 | 81 |
| Physics | Student 001 | 42 |
| French | Student 001 | 73 |
| Spanish | Student 001 | 78 |
| German | Student 001 | 67 |
| Engineering | Student 001 | 38 |
| Design & Tech | Student 001 | 57 |
| ... | ... | ... |
| ICT | Student 002 | 95 |
| Physical Education | Student 002 | 73 |
| Law | Student 002 | 37 |
| Sociology | Student 002 | 66 |
| Art & Design | Student 002 | 40 |
| Drama | Student 002 | 51 |
| Dance | Student 002 | 75 |
| General Studies | Student 002 | 37 |
| Maths 1 | Student 003 | 56 |
| Maths 2 | Student 003 | 77 |
| English Lang | Student 003 | 41 |
| ... | ... | ... |
| Sociology | Student 003 | 48 |
| Art & Design | Student 003 | 79 |
| Drama | Student 003 | 61 |
| Dance | Student 003 | 96 |
| General Studies | Student 003 | 50 |
| Maths 1 | Student 004 | 45 |
| Maths 2 | Student 004 | 73 |
| English Lang | Student 004 | 40 |
| English Lit | Student 004 | 60 |
| Chemistry | Student 004 | 77 |
| Biology | Student 004 | 56 |
| Physics | Student 004 | 69 |
| French | Student 004 | 90 |
| ... | ... | ... |
+--------------------+-------------+------------+
So Far I've created a pivot table with the subject as the Row Label, Student ID as the Column Label and the Sum of Test Scores as the Values, which gives me something like this:
+--------------------+-------------+-------------+-----+-------------+-------------+
| Row Labels | Student 001 | Student 002 | ... | Student 097 | Student 098 |
+--------------------+-------------+-------------+-----+-------------+-------------+
| Art & Design | 88 | 85 | ... | 79 | 91 |
| Biology | 81 | 123 | ... | 70 | 56 |
| Business Studies | 64 | 124 | ... | 47 | 51 |
| Chemistry | 89 | 100 | ... | 41 | 77 |
| Dance | 67 | 170 | ... | 96 | 36 |
| Design & Tech | 57 | 131 | ... | 31 | 89 |
| Drama | 35 | 130 | ... | 61 | 61 |
| Engineering | 38 | 125 | ... | 38 | 58 |
| English Lang | 64 | 102 | ... | 41 | 40 |
| English Lit | 88 | 160 | ... | 81 | 60 |
| French | 73 | 92 | ... | 69 | 90 |
| General Studies | 37 | 125 | ... | 50 | 63 |
| Geography | 41 | 117 | ... | 89 | 93 |
| German | 67 | 77 | ... | 33 | 89 |
| History | 85 | 176 | ... | 82 | 79 |
| Home Economics | 89 | 155 | ... | 71 | 46 |
| ICT | 85 | 179 | ... | 82 | 63 |
| Law | 46 | 102 | ... | 72 | 68 |
| Maths 1 | 78 | 98 | ... | 56 | 45 |
| Maths 2 | 63 | 137 | ... | 77 | 73 |
| Physical Education | 82 | 138 | ... | 30 | 80 |
| Physics | 42 | 108 | ... | 40 | 69 |
| Religious Studies | 66 | 113 | ... | 95 | 73 |
| Sociology | 87 | 152 | ... | 48 | 59 |
| Spanish | 78 | 152 | ... | 70 | 50 |
+--------------------+-------------+-------------+-----+-------------+-------------+
I've then used the large function adjacent to the table to give me the top 5 scores per row. However, what I need is the top 5 students ID's with the corresponding scores, rather than just the scores.
Apologies for the long post, I hope this all makes sense?
UPDATE -
Ideally I need an output similar to the following:
+--------------------+------------+------------+------------+------------+------------+
| | Result 1 | Result 2 | Result 3 | Result 4 | Result 5 |
+--------------------+------------+------------+------------+------------+------------+
| Art & Design | Student 92 | Student 88 | Student 85 | Student 62 | Student 94 |
| Biology | Student 86 | Student 74 | Student 63 | Student 90 | Student 60 |
| Business Studies | Student 56 | Student 66 | Student 77 | Student 97 | Student 97 |
| Chemistry | Student 86 | Student 67 | Student 95 | Student 58 | Student 56 |
| Dance | Student 91 | Student 65 | Student 76 | Student 82 | Student 87 |
| Design & Tech | Student 57 | Student 60 | Student 91 | Student 85 | Student 92 |
| Drama | Student 52 | Student 91 | Student 67 | Student 80 | Student 81 |
| Engineering | Student 58 | Student 82 | Student 95 | Student 88 | Student 71 |
| English Lang | Student 87 | Student 69 | Student 53 | Student 63 | Student 71 |
| English Lit | Student 93 | Student 75 | Student 78 | Student 91 | Student 77 |
| French | Student 76 | Student 64 | Student 92 | Student 63 | Student 80 |
| General Studies | Student 53 | Student 95 | Student 97 | Student 51 | Student 82 |
| Geography | Student 70 | Student 77 | Student 54 | Student 75 | Student 64 |
| German | Student 90 | Student 50 | Student 60 | Student 73 | Student 92 |
| History | Student 75 | Student 61 | Student 78 | Student 64 | Student 92 |
| Home Economics | Student 89 | Student 75 | Student 92 | Student 60 | Student 70 |
| ICT | Student 51 | Student 53 | Student 54 | Student 87 | Student 97 |
| Law | Student 92 | Student 86 | Student 67 | Student 55 | Student 50 |
| Maths 1 | Student 64 | Student 88 | Student 50 | Student 71 | Student 91 |
| Maths 2 | Student 71 | Student 82 | Student 93 | Student 64 | Student 64 |
| Physical Education | Student 80 | Student 70 | Student 89 | Student 82 | Student 64 |
| Physics | Student 93 | Student 78 | Student 94 | Student 55 | Student 53 |
| Religious Studies | Student 92 | Student 80 | Student 70 | Student 57 | Student 63 |
| Sociology | Student 58 | Student 51 | Student 91 | Student 68 | Student 71 |
| Spanish | Student 88 | Student 93 | Student 79 | Student 71 | Student 76 |
+--------------------+------------+------------+------------+------------+------------+
Pivot table is a good option.
Put subject and student id (in that order) into the Row Labels field. Place Test Score into Values field.
You need to right click on any of the values in the second column > sort > largest to smallest
After your create the above pivot,
paste special only the values to a new blank excel sheet.
Now transpose it into a new or same sheet... (shortcut is alt e + s+ e) ( so now subjects would be columns and student no.s as rows)
Now sort on subject from large to small (you will have sort manually as many number of times as the number of subjects
Alternate:
Ignore the above Pivot you made
Create a new pivot table with student no. in rows, subjects in columns and sort on subjects from large to small

JSF core tag <c:forEach/> value overflow while iterate

I have problem with core tag in JSF. Im using this tag for pagination button rendering. There is one big problem - when there is more then 127pages. Iteration value overflows. It looks like the iteration value is BYTE typed :-(. There is a code:
<c:forEach begin="#{listActionBean.start}" step="#{listActionBean.step}" end="#{listActionBean.allCnt}" var="i">
<ice:outputText value="#{i}"/>
<ice:outputText value="|"/>
</c:forEach>
Values on the listActionBean are INT typed. Its the same when i write:
<c:forEach begin="1" step="1" end="150" var="i">
<ice:outputText value="#{i}"/>
<ice:outputText value="|"/>
</c:forEach>
The output is:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -128 | -127 | -126 | -125 | -124 | -123 | -122 | -121 | -120 | -119 | -118 | -117 | -116 | -115 | -114 | -113 | -112 | -111 | -110 | -109 | -108 | -107 | -106 |
You can se the negative numbers. Is there some kind of switch to "longer" data type? or some another solution? Thank you for reply.
It works if you use varStatus instead of var:
<c:forEach begin="1" step="1" end="150" varStatus="status">
<h:outputText value="#{status.index}" />
<h:outputText value="|" />
</c:forEach>

Resources