Sum two rows in Excel based on multiple criteria - excel

I'd like to sum the lpqty and receivedqty columns for every two rows in Excel, and I'm struggling to find a way to do it. I want a list of the first 4 columns, where the week values only appear once, not twice as it is right now. (Ignore the iog column). So essentially I want it to look something like this:
2018 9 35 BCN1 59380 109963
2018 9 36 BCN1 356071 724178
I've tried with some SUM and OFFSET formulas, but I can't seem to make it work.

For the first 4 columns:
=INDEX(A:A,(ROW()*2-2))
starting in (say) J2
Then for the next 2 columns:
=INDEX(F:F,(ROW()*2-2))+INDEX(F:F,(ROW()*2-1))
(assumes all rows are strictly in pairs)

Related

Excel formula - Get the sum of each variable every 6 days

I have the following dataset where I want to get the sum of each variable every 6 days. I can get the total sum of every 6 days using
=SUM(OFFSET($A$2,,(COLUMNS($A$5:A5)-1)*6,,6))
And I can get the total sum of each variable using
=SUMIF(A1:S1,A1,A2:S2)
But I cant get the total sum of each variable within the block of 6 days. It won't increment when I drag the formula.
So the results should be
First batch Second batch Third batch
A B C A B C A B C
2 2 2 4 4 4 6 6 6
You can use SUMPRODUCT:
=SUMPRODUCT((1:1=A6)*2:2*(COLUMN(1:1)>(INT((COLUMN()-1)/3)*6))*(COLUMN(1:1)<=(INT((COLUMN()-1)/3+1)*6)))
Edit:
To shift the column by five position, you will need to change the following parameters in the formula:
Full row range change to exact range, i.e. 1:1 to e.g. $F$1:$W$1
Change COLUMN()-1 to COLUMN()-3
If you also want to change the number of columns to be summed, additionally replace the factor of 6 with a 7-1 for seven columns or 36-30 for thirty-six columns.
So formulas looks like:
batch of 6 cols
=SUMPRODUCT(($F$1:$W$1=F6)*$F$2:$W$2*(COLUMN($F$1:$W$1)>=((INT((COLUMN()-3)/3))*6))*(COLUMN($F$1:$W$1)<((INT((COLUMN()-3)/3+1))*6)))
batch of 7 cols
=SUMPRODUCT(($F$1:$Z$1=F6)*$F$2:$Z$2*(COLUMN($F$1:$Z$1)>=((INT((COLUMN()-3)/3))*7-1))*(COLUMN($F$1:$Z$1)<((INT((COLUMN()-3)/3+1))*7-1)))
batch of 36 cols
=SUMPRODUCT(($F$1:$WW$1=F6)*$F$2:$WW$2*(COLUMN($F$1:$WW$1)>=((INT((COLUMN()-3)/3))*36-30))*(COLUMN($F$1:$WW$1)<((INT((COLUMN()-3)/3+1))*36-30)))
Instead of creating a really, really, really complex formula that can be dragged right, I suggest you add a row to the data at the top that identifies the batch number. Then you can use that batch number as an additional parameter in the Sumifs(). you can hide the rows with the batch numbers if they upset your spreadsheet design.
=SUMIFS(3:3,1:1,A16,2:2,A17)
This is far easier than creating a formula that dynamically adjusts references in tiered steps of three and six.

Sumproduct - counting equal pairs of numbers (and filtering them)

In columns D&E I have a list of scores for a game, where D is points for and E is points against, like so
D E
1 3
4 2
3 3
3 1
I'm trying to create a formula that displays a win / draw / loss record based on whether column D is larger, equal to or smaller than column E. In this example it would display 2 / 1 / 1.
So far I have this
=(SUMPRODUCT(--(D12:D200>E12:E200)))&" / "&SUMPRODUCT(--(D12:D200=E12:E200))&" / "&(SUMPRODUCT(--(D12:D200<E12:E200)))
But there are two issues. One is that all the blank rows are being counted as equals, so the result is coming out as 2 / 186 / 1.
The second is that in another column I have a list of days of the week, and I would like to be able to filter out rows by day and have the results reflect this. I have different formulas using SUBTOTAL instead of SUM to count overall number of points, which works fine. But I don't know what the equivalent change I need to make would be for my formula. Any help would be appreciated.
As for your first issue, your formula indeed takes blanks into account and treats them as equals. You can adjust your middle SUMPRODUCT formula to omit the blanks, just like that:
=SUMPRODUCT(ISNUMBER(D12:D200)*(--(D12:D200=E12:E200)))
The second question is regarding filtering out rows by the day of the week. Here's the view before "Day" filter is applied - as you can see we have 5 wins (blue), 4 draws (orange) and 3 losses (green).
You need to use the following formula to make SUMPRODUCT dynamic (i.e. it will react to filtering out rows):
=SUMPRODUCT(SUBTOTAL(3,OFFSET(F12:F200,ROW(F12:F200)-ROW(F12),,1)),--(D12:D200>E12:E200))&" / "&SUMPRODUCT(SUBTOTAL(3,OFFSET(F12:F200,ROW(F12:F200)-ROW(F12),,1)),ISNUMBER(D12:D200)*(--(D12:D200=E12:E200)))&" / "&SUMPRODUCT(SUBTOTAL(3,OFFSET(F12:F200,ROW(F12:F200)-ROW(F12),,1)),--(D12:D200<E12:E200))
Here's the result just for Monday:

Excel: Cumulative sum of min values of 2 columns without needing to create an extra column

I have two columns that I need to find the minimum value of, and then create a cumulative sum of them. I can do this by creating an extra column to hold the min value and then cumulative sum them, e.g.:
Col1 Col2 min(Col1, Col2) Cumulative Sum of Mins
1 3 1 1
4 2 2 3
3 5 3 6
Is there a way of doing this without creating the extra column?
I've tried sum(if(A$2:A2 < B$2:B2, A$2:A2, B$2:B2)) which I found (and modified) from another similar-but-not-similar-enough question, but this appears to just find the lowest value in the entire range and output that into a single cell; copying and pasting the formula into the other fields results in:
A value used in the formula is of the wrong data type
put this in C2 and copy down:
=IFERROR(--C1,0)+MIN(A2:B2)
Another approach is with SUMPRODUCT
=SUMPRODUCT(($A$2:A2<$B$2:B2)*($A$2:A2)+($A$2:A2>$B$2:B2)*($B$2:B2))
But this is an array type formula and as such every line this is copied down will increase the number of calculations exponentially. If too many lines are used the user will see a time delay in the calculations.

All combinations of 4 out of 7 columns with totals using excel

I have 7 columns to choose from and I need to pick 4 of those columns and generate a total for each row. I also need every combination of 4, which means I'll have 35 new columns with the totals for each of those combinations showing in each row. I need the code for this and if it can be done only using Excel. Here is an image of the columns and the grayed ones are the 7 columns I'm talking about. My knowledge of Excel is very limited. There are over 1,500 rows if that matters.
multi step approach that is going to use some helper rows. there may be a more elegant formula that will do this, and much slicker options in VBA, but this is a formula only approach.
Step 1 - Generate List of Column Combination
To generate the list 4 helper rows will need to be insert at the top of your data. either above or below you header row. These 4 rows will represent the column number you are going to pick. To keep the math simpler for me I just assumed the 1 for the first column and 7 for the last column. those numbers will get converted to later to account for column in between in your spreadsheet. For the sake of this example The first combination sum will occur in column AO and the first helper row will be row 1. The first combination will be hard coded and it will seed the pattern for the remainder of column combinations. Enter the following values in the corresponding cells:
AO1 = 1
AO2 = 2
AO3 = 3
AO4 = 4
In the adjacent column a formula will be placed and copied to the right. It will automatically augment the bottom value by 1 until it hits its maximum value at which point the value in the row above will increase by 1 and the the value of the current will be 1 more than the cell above. This will produce a pattern that covers all 35 combinations by the time column BW is reached. Place the formulas below in the appropriate cell and copy to the right:
AP1
=IF(AO2=5,AO1+1,AO1)
AP2
=IF(AO2=5,AP1+1,IF(AO3=6,AO2+1,AO2))
AP3
=IF(AO3=6,AP2+1,IF(AO4=7,AO3+1,AO3))
AP4
=IF(AO4=7,AP3+1,AO4+1)
Step2 - Sum The Appropriate Columns
I was hoping to use a some sort of array type operation to read through the column reference numbers above, but I could not get my head around it. Since it was just 4 entries to worry about I simply added each reference manually in a SUM function. Now the important thing to note is that we will be using the INDEX function over the 13 columns that cover the range of your columns so to convert the index number we figured out above, to something that will work to grab every second row, the number that was calculated will be multiplied by 2 and then 1 will be subtracted. That means 1,2,3,4 for the first column combination becomes 1,3,5,7. You can see this in the following formula. Place the following formula in the appropriate cell and copy down and to the right as needed.
AO5
=INDEX($AB5:$AN5,AO$1*2-1)+INDEX($AB5:$AN5,AO$2*2-1)+INDEX($AB5:$AN5,AO$3*2-1)+INDEX($AB5:$AN5,AO$4*2-1)
pay careful attention to the $ which will lock row or column reference and prevent them from changing as the formula is copied.
Now you may need to adjust the cell references to match your sheet.

excel averaging every 10 rows

I have a big data set which has about 9000 rows. I have a few variables for every year from 1960 onwards, and I need to average them in ten year bins. So I have something like:
1
2
3
4
2
3
4
5
Now I need to average the first ten rows, then the next ten, and so on, for all 9000-odd rows. I can do that, but then I get all these rows averaged in the middle which I don't need, and I can't go about deleting those many rows. There has to be an easy way to do this, surely?
Would appreciate any help!
Suppose your data starts from A1. Try this one in B1:
=AVERAGE(INDEX(A:A,1+10*(ROW()-ROW($B$1))):INDEX(A:A,10*(ROW()-ROW($B$1)+1)))
and drag it down.
in B1 it would be =AVERAGE(A1:A10)
in B2 it would be =AVERAGE(A11:A20)
in B3 it would be =AVERAGE(A21:A30)
and so on.
General case
If your data starts from An (where n is 2,3,4,...), use this one:
=AVERAGE(INDEX(A:A,n+10*(ROW()-ROW($B$1))):INDEX(A:A,n-1+10*(ROW()-ROW($B$1)+1))
where you should change n to 2,3,4,...

Resources