How to multiply the reverse of a column with another column in excel? - excel

Suppose i need to multiply the entries in these two columns in the following order in MS Excel
This is just an example
A | B
1 | 5
2 | 10
3 | 15
4 | 20
bolck1:1*5
block2:(2*5)+(1*10)
block3:(3*5)+(2*10)+(1*15)
block4:(4*5)+(3*10)+(2*15)+(1*20)
how would i do it?
I used SUMPRODUCT(A4:A1,B4:B1) but it returned the same old sum 150 as was the case with SUMPRODUCT(A4:A4,B1:B4).

You could add a helper column. In C1 put:
=SUMPRODUCT(A1*INDEX($B$1:$B$4,1):INDEX($B$1:$B$4,COUNT($B$1:$B$4)-(ROW(1:1)-1)))
Drag it down then total the results:

Related

Spreadsheet - Im trying to find the sum of the top n numbers in two columns

-UPDATED- Answered, thanks for all who helped.
Consider the following Google spreadsheet:
A B C D E
1 John | Bob | Sue | Tony
2 h1 2 | 1 | 3 | 2
3 h2 3 | 3 | 4 | 2
4 h3 1 | 2 | 1 | 3
5 h4 2 | 2 | 3 | 1
6 h5 2 | 1 | 1 | 3
7 h6 1 | 2 | 2 | 1
8 h7 1 | 2 | 1 | 3
Team | Player1 | Player 2 | Score
1 | John | Sue | ?
2 | Bob | Tony | ?
Each team is made of two partners, e.g. John and Sue. Each row contains a match: the team's score is the best of each member's. The team total score of the game is the sum of the match scores.
In the example:
Team 1 : John & Sue. Match scores: (3,4,1,3,2,2,1). Total score = 16.
Team 2 : Bob & Tony. Match scores: (2,3,3,2,3,2,3). Total score = 18.
Another example would be two golfers working as team and the best score between them is counted per hole, the at the end we add those up.
Can this be done using a spreadsheet?
To get the desired result, the formula comes up quite complicated:
=SUMPRODUCT(IF(MMULT((B12=$B$1:$E$1)*$B$2:$E$8,ROW(A1:A4)^0)>MMULT((C12=$B$1:$E$1)*$B$2:$E$8,ROW(A1:A4)^0),(B12=$B$1:$E$1)*$B$2:$E$8,(C12=$B$1:$E$1)*$B$2:$E$8))
but works in both Excel and GS
In Excel you can use the LARGE() function. It is the easiest option but a bit verbose.
If you want to the sum of the top 3 values in a column/row:
= large(A1:A10, 1), large(A1:A10, 2) + large(A1:A10, 3)
In Excel
If one has the new dynamic array formula LET():
=LET(x,INDEX($B$2:$E$8,0,MATCH(I2,$B$1:$E$1,0)),y,INDEX($B$2:$E$8,0,MATCH(J2,$B$1:$E$1,0)),SUMPRODUCT(((x>y)*x)+((y>=x)*(y))))
Else
=SUMPRODUCT(((INDEX($B$2:$E$8,0,MATCH(I2,$B$1:$E$1,0))>INDEX($B$2:$E$8,0,MATCH(J2,$B$1:$E$1,0)))*INDEX($B$2:$E$8,0,MATCH(I2,$B$1:$E$1,0)))+((INDEX($B$2:$E$8,0,MATCH(J2,$B$1:$E$1,0))>=INDEX($B$2:$E$8,0,MATCH(I2,$B$1:$E$1,0)))*(INDEX($B$2:$E$8,0,MATCH(J2,$B$1:$E$1,0)))))
Either of the following formulas will produce the desired sums of 16 and 18 (tested on my machine):
=ArrayFormula(SUM(IF($B$2:$B$8>$D$2:$D$8,$B$2:$B$8,$D$2:$D$8)))
=SUMPRODUCT(IF($B$2:$B$8>$D$2:$D$8,$B$2:$B$8,$D$2:$D$8))
Adjust to B->C and D->E for Bob + Tony. These formulas work by operating on arrays. They evaluate the IF statement once per cell in the B2:B8 range and generate an array of values ({3,4,1,3,2,2,1}). Then SUM or SUMPRODUCT will sum those values. ArrayFormula is necessary to force SUM to deal with the IF as an array.
Further customization can be built from here as desired. Play around with ArrayFormula and SUMPRODUCT as they have much more powerful use cases than this and have parallels in other spreadsheet softwares including Excel.

Highlighting 3 Cells If Condition Met

I have a question regarding conditional formatting in Excel.
I have a sheet that acts as a calendar for my team members whereby calendar dates are in row 1 and each person’s name in column A. Each person occupies 3 rows unmerged, so the first name occupies rows 2 to 4, the next person 5 to 7, and so on. If the person will not be at work on a particular day, a “out of office” will be written on the respective first row. Assuming that 1 January occupies column B and that the first person will be out of office then, the value of cell B2 will be “out of office”. Using conditional formatting, I was able to highlight B2:B4 without issues. However, I was only able to do this for a single person.
I would like to know if there is a way of extending some conditional formatting formula to all 20 members so that I do not have to do the same thing for another 19 times (more if new members join).
So if any cell in column B contains "out of office" then this cell and the next 2 cells below shall be formatted? Or in other words a cell shall be formatted if itself or the cell 1 row above or the cell 2 rows above contains "out of office"?
This can be achieved using the following conditionla formatting rule for whole column B:
Conditional formatting rule based on formula:
=OR(B1="out of office",B1048576="out of office",B1048575="out of office")
Background: In CF the references are like a carousel. So what in B1 is
=OR(B1="out of office",B1048576="out of office",B1048575="out of office")
will be in B2 then
=OR(B2="out of office",B1="out of office",B1048576="out of office")
(B1048576 plus 1 row = B1)
and in B3 then
=OR(B3="out of office",B2="out of office",B1="out of office")
If you are using Conditional Formatting Formula, then you can use the following code to retrieve the value from the current or previous row in the pattern 2, 5, 8, 11, etc:
INDEX(A:A, 3*INT((ROW()-2)/3)+2, 1)
To break it down: Using INDEX(A:A and , 1) will get us a row from Column A (of course, this moves across as your Format Condition does) - the row itself is specified by the ungainly mess in the middle: 3 * INT((ROW() - 2) / 3) + 2
Putting that kludge into plain-text: Start with the current row, subtract 2, round down to a multiple of 3, then add 2 again
Row | Subtract 2 | Round down to 3 | Add 2
1 | -1 | -3 | -1
2 | 0 | 0 | 2
3 | 1 | 0 | 2
4 | 2 | 0 | 2
4 | 3 | 3 | 5
.. | .... | .... | ..
28 | 26 | 24 | 26
29 | 27 | 27 | 29
30 | 28 | 27 | 29
31 | 29 | 27 | 29
32 | 30 | 30 | 32
So - you can now just apply whole-column conditional formatting, with a formula something like this:
=INDEX(A:A, 3*INT((ROW()-2)/3)+2, 1) = "Out of Office"
And it will apply to blocks of 3 rows at a time in each column, starting at Row 2 (or -1)

Excel array formula to find row of largest values based on multiple criteria

Column: A | B | C | D
Row 1: Variable | Margin | Sales | Index
Row 2: banana | 2 | 20 | 1
Row 3: apple | 5 | 10 | 2
Row 4: apple | 10 | 20 | 3
Row 5: apple | 10 | 10 | 4
Row 6: banana | 10 | 15 | 5
Row 7: apple | 10 | 15 | 6
"Variable" sits in column A, row 1.
"Fruit" refers to A2:A6
"Margin" refers to B2:B6
"Sales" refers to C2:C6
"Index" refers to D2:D6
Question:
From the above table, I would like to find the row of two largest "Sales" values when Fruit = "apple" and Margin >= 10. The correct answer would be values from row 3 and 6. I have tried the following methods without success.
I have tried
=LARGE(IF(Fruit="apple",IF(Margin>=10,Sales)),{1,2}) + CSE
and this returns 20 and 15, but not the row.
I have tried
=MATCH(LARGE(IF(Fruit="apple",IF(Margin>=10,sales)),{1,2}),Sales,0)+1
but returns row 2 and 6 as the first matches to come up are the 20 and 15 from "banana" not "apple".
I have tried
=INDEX(D2:D7,LARGE(IF(Fruit="apple",IF(Margin>=10,ROW(Sales)-ROW(INDEX(Sales,1,1))+1)),{1,2}),1)
But this returns row 7 and 5 (i.e. "Index" 6 and 4) as these are just the first occurrences of "apple" starting from the bottom of the table. They are not the largest values.
Can this be done with an Excel formula or do would I need a macro? If macro, can I please get help with the macro? Thank you!
use this formula:
=INDEX(D:D,AGGREGATE(15,6,ROW($A$2:$A$7)/(($B$2:$B$7>=10)*($A$2:$A$7="apple")*($C$2:$C$7 = AGGREGATE(14,6,$C$2:$C$7/(($B$2:$B$7>=10)*($A$2:$A$7="apple")),F2))),1))
I put 1 and 2 in F2 and F3 respectively to find the first and second.
Edit #1
to deal with duplicates we need to add (COUNTIF($G$1:G1,$D$2:$D$7) = 0). The $G$1:G1 needs to refer to the cell directly above the first placement of this formula. So the formula needs to start in at least row 2.
=INDEX(D:D,AGGREGATE(15,6,ROW($A$2:$A$7)/((COUNTIF($G$1:G1,$D$2:$D$7) = 0)*($B$2:$B$7>=10)*($A$2:$A$7="apple")*($C$2:$C$7 = AGGREGATE(14,6,$C$2:$C$7/(($B$2:$B$7>=10)*($A$2:$A$7="apple")),F2))),1))

tabulate frequency counts including zeros

To illustrate the problem, consider the following data: 1,2,3,5,3,2. Enter this in a spreadsheet column and make a pivot table displaying the counts. Making use of the information in this pivot table, I want to create a new table, with counts for every value between 1 and 5.
1,1
2,2
3,2
4,0
5,1
What is a good way to do this? My first thought was to use VLOOKUP, trapping any lookup error. But GETPIVOTDATA is apparently preferred for pivot tables. In any case, I failed with both approaches.
To be a bit more specific, assume my pivot table of counts is "PivotTable1" and that I have already created a one column table holding all the needed lookup keys (i.e., the numbers from 1 to 5). What formula should I put in the second column of this new table?
So starting with this:
To illustrate the problem, consider the following data: 1,2,3,5,3,2. Enter this in a spreadsheet column and make a pivot table displaying the counts.
I then created the table like this:
X | Freq
- | ---------------------------------------------
1 | =IFERROR(GETPIVOTDATA("X",R3C1,"X",RC[-1]),0)
2 | =IFERROR(GETPIVOTDATA("X",R3C1,"X",RC[-1]),0)
3 | =IFERROR(GETPIVOTDATA("X",R3C1,"X",RC[-1]),0)
4 | =IFERROR(GETPIVOTDATA("X",R3C1,"X",RC[-1]),0)
5 | =IFERROR(GETPIVOTDATA("X",R3C1,"X",RC[-1]),0)
Or, in A1 mode:
X | Freq
- | -----------------------------------------
1 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",F3),0)
2 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",F4),0)
3 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",F5),0)
4 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",F6),0)
5 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",F7),0)
The column X in my summary table is in column F.
Or as a table formula:
X | Freq
- | -------------------------------------------
1 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",[#X]),0)
2 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",[#X]),0)
3 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",[#X]),0)
4 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",[#X]),0)
5 | =IFERROR(GETPIVOTDATA("X",$A$3,"X",[#X]),0)
That gave me this result:
X | Freq
- | ----
1 | 1
2 | 2
3 | 2
4 | 0
5 | 1
If performance is not a major concern, you can bypass the pivot table and use the COUNTIF() function.
Create a list of all consecutive numbers that you want the counts for and use COUNTIF() for each of them with the first parameter being the range of your input numbers and the second being the number of the ordered result list:
A B C D
1 1 1 =COUNTIF(A:A,C1)
2 2 2 =COUNTIF(A:A,C2)
3 3 3 =COUNTIF(A:A,C3)
4 5 4 =COUNTIF(A:A,C4)
5 3 5 =COUNTIF(A:A,C5)
6 2

List for minimum of corresponding columns excel

I have four columns with numbers. I would like to calculate in a separate cell a a sum. The sum will consist of the minimums of corresponding cells in these four columns
Example:
A | B | C | D
------------------
[1] 1 | 2 | 3 | 2
[2] 4 | 3 | 1 | 6
[3] 0 | 1 | 8 | 2
[4] 5 | 5 | 2 | 2
I need a formula that would calculate in a cell the sum of 1 + 1 + 0 + 2 where
I would like to use an array formula to do this calculation, but cannot figure out how to use minimum to accept arrays and return an array of minimums.
Thanks!
Assuming that data is in A1:D4:
SUBTOTAL(5,OFFSET(A1:D1,ROW(A1:D4)-MIN(ROW(A1:D4)),))
will give you the required, intermediate array to be used in further constructions as you see fit (with the caveat that that construction is one which is capable of coercing the necessary array from the above, of course).
Regards

Resources