Excel: How do I sum cell values every nth colum - excel

I have the following table:
and I'd like to have the total for each player but values are every 3 columns.
As you can see from the picture on the bottom part I wrote what manually I should enter.
For player 1
=SUM(D3;G3;J3...)
Player 2
=SUM(D4;G4;J4...)
and so on. What formula should I use to calculate automatically every 3 columns? I know how the MOD works but on the net I found too many examples each one using different methods and none worked so far. Can anyone help me please or point me to the right direction to understand how it works to get this data since I'll be using this a lot (get value from cell every nth column).
thanks

It looks like you should just be using SUMIFS here:
=SUMIFS(3:3,$2:$2,"TOT")
This will sum every value on row 3 (Player 1) where the value in row 2 is "TOT" (every 3rd column). Put this in cell B18 and just copy down in your column B.
Or, in case you change your column labels, you can refer to cell D2 instead of typing "TOT" in the formula:
=SUMIFS(3:3,$2:$2,$D$2)

Try this, it will total all the cells that occur every 3 columns beginning at column D. Z3 can be increased to any column you require:
=SUMPRODUCT((D3:Z3)*(MOD(COLUMN(D3:Z3)-1,3)=0))

The explanation on how it works can be found here (I advise you to bookmark this site for future references. They have many other helpful formulas and functions).
Applying this formula to your reality should be something like this for Player 1 (Not tested. Adjust the ranges as required):
=SUMPRODUCT(--(MOD(COLUMN(D3:Z3)-COLUMN(D3)+1,3)=0),D3:Z3)

Related

Sum Multiple Rows Sharing A Common Index Value

I can't seem to find any examples for this exact Index-Match function problem on this site.
The green boxes have the value of "x". What I'd like to achieve is to find every instance of "x" in column G (this will be dragged for all columns onwards), and essentially look-up in Column D for it's hours equivalent and sum them in a one cell calculation for each week.
e.g. in this section of the spreadsheet, it will sum: 3.75 + 7.5 + 3.75 + 15 = 30 hours
I started with: =INDEX($D$3:$D$157,MATCH("x",G3:G157,0)) which returns the right answer, i.e. 3.75 hours, so I attempted to loop the function using the following:
=AGGREGATE(9,0,INDEX($D$3:$D$157,,MATCH("x",G3:G157,0)))
Though this returns an #REF! error message.
This is a link to a screenshot of the spreadsheet for reference. (I don't have the necessary reputation to post the image with the question).
Any help on this problem would be appreciated. I would prefer an in-cell function solution, as I'm not confident with VBA.
G2: =SUMIF(G$3:G$157,"x",$D$3:$D$157)
and fill right as far as required.
It would be easier if you could add an hidden column with a formula "=IF(G7="x";D7;0)" and calculate the respective hours based on the presence of "x" in column G. Then you can just simply get the total for this hidden column. It is more readable and easy to maintain.

averaging every nth rows and excluding values

I want to average every 5 rows but also to exclude in the average values that are less than 50. This is the command to average every 5 rows.
=AVERAGE(OFFSET($L$3,(ROW()-ROW($P$2))*5,,5))
This is the command to exclude values less than 50
=AVERAGEIF(L3:L8,">50")
How do I combine those two in one command?
Thanks to a colleague of mine, the following works like a gem.
=IFERROR(AVERAGEIF(OFFSET($L$3,(ROW()-ROW($P$2))*5,,5),">50"),0)
As long as you have Excel 2016, a SUMPRODUCT formula will work.
=SUMPRODUCT((MOD(ROW($A$1:$A100),5)=0)*($A$1:$A$100<50)*$A$1:$A$100)/SUMPRODUCT((MOD(ROW($A$1:$A100),5)=0)*($A$1:$A$100<50)*1)
I assumed your data was in A1:A100 so update that as needed. And in the MOD formula, I used 5 for ever 5th row. If you need to change that, change the 5 in MOD formulas. Lastly, the formula does not include the value 50 since you stated you wanted less than 50.
'Tiny' Differences
Correction
=IFERROR(AVERAGEIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">50"),0)
Visualize
Let's first visualize what you're actually doing.
For every five rows in column L you are displaying the average of the values, if they are greater than or equal to 50. (in this example) in column G:
For L3:L8 in G2,
for L9:L13 in G3,
for L14:L18 in G4 etc.
Issues
The 1st issue is that the formula is written exclusively for the
2nd row. If you want the first result to be displayed in the first row, the formula will result in a REF! error.
If you want to display the first result in the 1st row you have to
change L$2 to L$1:
=IFERROR(AVERAGEIF(OFFSET(L$3,(ROW()-ROW(L$1))*5,,5),">50"),0)
or for the 3rd row you have to change L$2 to L$3:
=IFERROR(AVERAGEIF(OFFSET(L$3,(ROW()-ROW(L$3))*5,,5),">50"),0)
The 2nd issue is that you are doing something in column L and for
no obvious reason you are using column P in your formula. You could
have used any column Z, AN or CG, but your doing stuff in
column L, so use L.
The 3rd issue is that you have locked the columns $L which means where
ever you put the formula in a single row, the result will be the same. If
you don't lock them, you can copy the formula e.g. to the right and
it will display the results for columns M, N, O etc.:
Other Formulas
=SUM(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5))
=COUNT(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5))
=AVERAGE(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5))
=SUMIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">50")
=COUNTIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">50")
AVERAGEIF is available in Excel from version 2007, but for older versions the following formula can be used instead:
=IF(COUNTIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">"&50)=0,0,SUMIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">"&50)/COUNTIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">"&50))
It first checks if COUNTIF results in 0. If it does it displays 0, otherwise it divides SUMIF with COUNTIF.

Excel: Get values in non-adjacent cells based on multiple criteria

I have an excel sheet sort of like this:
I'm trying to figure out how to get the totals in cells B1 through B4.
I tried INDEX-MATCH, where I tried to match the words in A1:A4 with the words in row 7, get the numbers relative to them, and then sum them, but it was a lot of Google searching and stabbing in the dark -- every attempt returned an error.
I also tried to INDEX-MATCH the words in A1:A4 with row 7, and then nest a VLOOKUP in there where it'd get the number relative to "visits:" but that didn't work at all either.
Is INDEX-MATCH even the correct function? Any help would be much appreciated, I'm not even sure what to Google anymore.
EDIT: I need to use a search function of some kind, like the INDEX-MATCH method, rather that static formulas because the sheet will change periodically and I don't want to have to update the formula every time I add an animal.
Your data table is unusual in structure.
However, if you are gong to keep a fixed rule such that the number of visits is always offset 2 rows and 1 column from the animal type(and that itself is always in row 7), you could do:
In B1:
=SUM(IF($A$7:$AAA$7=$A1, $B$9:$AAB$9, 0))
Confirm with Ctrl-Shift-Enter, and then copy down..
DOes this work?
=SUM(IF($B$7=A1,$C$9,0),IF($D$7=A1,$E$9,0),IF($F$7=A1,$G$9,0),IF($H$7=A1,$I$9,0))
I'm not sureto have fully grasped your challenge. Yet it seems the following solution would work:
Add the following formula in each box where the number of visits is added as
=+SUMIF($A$1:$A$end;animal;$B$1:$B$end)
Where end is a number of the last cell in the first and second columns data contain the data.
And animal is the cell that contains the name of the animal.
Therefore in your simple example, the formulas on cells C9;E9;G9 and I9 would be respectively:
=+SUMIF($A$1:$A$4;B7;$B$1:$B$4) ; =+SUMIF($A$1:$A$4;D7;$B$1:$B$4); =+SUMIF($A$1:$A$4;F7;$B$1:$B$4) and =+SUMIF($A$1:$A$4;H7;$B$1:$B$4).

Dynamically sum row values based on column headers? - Excel

Need solutions for the queries posted in the below link,
http://www.mrexcel.com/forum/excel-questions/334740-dynamically-sum-row-values-based-column-headers.html
Having PersonWeek as separate column with sum of weeks should be displayed.
Quest: Dynamically sum row values based on column headers?
It is good form to re-post the question in its entirety on this site; nevertheless:
What you are looking for is relatively straight forward. There are a lot of ways to accomplish this but I suggest that you use combination of the 'Match' function and the the 'Offset' function. The Offset function creates a range based on a given start point, moving up/down / left/right as indicated, with a given height / width. For example:
=Offset(B2,1,2,3,4)
Indicates the range D3:G5. This is the range given by starting at cell B2, moving 1 row down and 2 columns to the right, and going for a total of 3 rows and 4 columns.
So the remaining point is to determine where to start and stop your offset.
First, the first field in your Offset function will be cell A1, as that is the top-left corner of your data table. To find how many rows to move down, you need to find what project you are referring to (I will assume that cell A6 is where you enter the project name that you care about, A7 is where you enter the first week you care about, and A8 is where you enter the last week you care about). To find how many rows to move down from A1, then, use Match:
=Match(A6, A2:A5,0)
To find how many columns to move to the right to find your first week, use Match again:
=Match(A7, B1:G1,0)
Assuming you only want to look at a single project, we know how high we want the range to be (1).
To find how wide we want the range to be, we need to know your ending week, less your starting week:
=(Match(A8,B1:G1,0)-Match(A7, B1:G1,0))
So the whole thing together will be:
=Offset(A1,Match(A6, A2:A5,0),Match(A7, B1:G1,0),1,Match(A8,B1:G1,0)-Match(A7, B1:G1,0))
Now the only thing left is to wrap the newly defined range in a 'sum' function, like so:
=Sum(Offset(A1,Match(A6, A2:A5,0),Match(A7, B1:G1,0),1,Match(A8,B1:G1,0)-Match(A7, B1:G1,0)))
This formula will create an error if someone enters a project name / weekname in a way that isn't found in your table - so in cells A6-A8 you may want to use data validation to only allow those names to be entered - let me know if you would like elaboration on that.

Increment constant in Excel Formula

Suppose, in Excel, I have a formula =$C$8+1, what must I add to the 1 such that when I drag, it becomes $C$8+2?
Can this be done?
Below is my actual formula.. I wish to increment 1 to 2 such that it becomes =2
IF((NOW()-$C8)=1,"1","0")
Well.. there might be several ways to do it, but the only one I have in the top of my head is using the =ROW() function.
Let's say you're starting the formula at row 5.
=IF((NOW()-$C8)=ROW()-4,"1","0")
The =ROW() will return the row number you currently are (i.e. 5, in this case). Thus, in the first row we'll have =1 (from 5-4) and then =2 (6-4) and so on.
Still, it seems you're comparing dates, right? I'd say you'd need to truncate the values to have a day comparison between them...
=IF((TRUNC(NOW())-TRUNC($C8))=ROW()-4,"1","0")
Hope it helps... or at least give you a path to chose your solution.

Resources