Let's say I have Row 21 titled "Stadium". Cells in this row contain any integer between 1 and 24. I need to create another cell with some formula that will do the following:
Find all cells in Row 21 that contain the value (integer) "6". Then, it needs to average the sum of all of the cells that are a given number of cells (such as nineteen) above the cells containing 6. For example:
The Spreadsheet I'm Using
Since Row 21 (Stadium) contains the value 6 twice, I need the highlighted cell (which I chose randomly) to output the average of cells B2 and E2 (which are nineteen cells above). So whatever formula I put in should output 11.5 which is the average number of Boost items obtained for every Stadium #6 event. If I wanted to find the average number of Glide items obtained for every Stadium #3, for example, the formula would output 13 since only one Stadium #3 is recorded.
I would change the values in the formula manually depending on what stadium number I'm looking for (i.e. 6 or 3) or what item I am looking for (i.e Boost or Glide).
The reason that the formula needs to be set up this way is because data will be continually entered into this spreadsheet and that data entry will never be finished.
I figure that this might involve the OFFSET and AVERAGE functions but I have no idea what else this would involve. This is where I need your help!
Please consider the following solution:
=AVERAGE(IF(B21:G21=6,INDIRECT("B"&MATCH("Boost",A:A,0)&":G"&MATCH("Boost",A:A,0)),""))
Inputted as an array formula using CTRL + SHIFT + ENTER. Explaining the logic first in the indirect; it finds the row matching column A to the item you want to report on (ie Boost or Glide). With the row it creates a range in the indirect referencing the row you want values for. It then generates an array with only the values for the columns of the stadium (6 in this case) by comparing the array of the same dimension formed from the Stadium row to your target stadium. Lastly it takes the average of the resulting array to output the expected answer. Regards,
Related
I am having the following problem:
I have a list of items number and descriptions starting at A5 and going down, at B5 I have the total sold quantity over a year, C5 corresponds to sales price per unit and D5 to its COGS per unit.
Further down, starting in cell A12 I have a specific item number and its description. I have then the quantity sold of this item each month (cells B13:D13) and underneath I want to have the sales quantity per month times the unit sales price of that item (that is in cells B14:D14).
To do so, from B14 I look up the item number and description in A12, in the list of items I mentioned before ($A$5:$D$7) in order to get the price for that item and then multiply it by that months sold quantity.
The problem with this approach is that when I drag that result along, over the following months, it stops searching the value at A12 and instead looks for the item value at B12, then C12 etc etc.
So in order to fix that I locked the value at A12 using the formula '=B13*VLOOKUP(INDIRECT(ADDRESS(ROW(Artikel)+ROWS(Artikel)-4;COLUMN(Artikel)+COLUMNS(Artikel)-4);TRUE);ItemSales;3;FALSE). Thanks to that, I am able to drag the result of the first month over the next months and to get a right result.
However, I would like to copy the table with the monthly results ( $B$13:$D$15 ) and paste it some rows bellows, and that the item referenced is not anymore the previous one at A12, but a new one let’s say in A26.
I achieve that with the formula k=VLOOKUP(OFFSET(INDIRECT(ADDRESS(ROW();COLUMN()));-2;-1;1;1);ItemSales;3;FALSE)*B27 but this formula doesn’t hold the item number and description value when dragged along, so I don’t get to combine them both
Any ideas how I can make it happen??
I have designed two formulas for you. The first one is for column A. Enter it in A12 and copy down, 6 rows for each row in your Item_Sales range.
=IF(MOD(ROW(),6)=0,INDEX(Item_Sales,INT((ROW()-12)/6)+1,1),IFERROR(INDEX({"Total quantity","Total Sales","Total COGS"},MOD(ROW(),6)),""))
Note that the number 12, wherever it occurs in the formula refers to row 12, where your named range "Artikel" starts. It's the first row where the first item in "Item_Sales" must appear. The number 6 refers to the number of rows in one data set, essentially Rows(12:17) for the first set, Rows(18:23) for the second etc. Your row 16 is hidden, row 17 blank. If you want the formula to write anything there expand the array {"Total quantity","Total Sales","Total COGS"}
The other formula is for cell B13. From there you can copy it to B14:B15. You can also copy B13:B15 to B19 but in its present form the formula will throw an error in B16:B18.
=INDEX(Item_Sales,INT((ROW()-12)/6)+1,MOD(ROW(),6)+1)*IF(ISNUMBER(B12),B12,1)
Again, the meaning of numbers 12 and 6 is as explained above. You would need to modify them if your data or display format changes in the future.
For your better understanding, I used the INDEX function which takes a 2D range and extracts values from it based on coordinates. INDEX(Item_Sales, 1, 2) returns the value of the cell in the first row, second column of the range defined as "Item_Sales". Of course, these numbers can be calculated.
The other functions I use are INT() and MOD(). Int(5/6) returns 0, as does INT(1/6). This function can be used to locate the first row in a set the repeats every 6 rows. INT(13/6) returns 2, INT(19/6)=3. These calculations identify the row numbers in Item_Sales referenced in Artikel.
MOD returns the modulus of a division. MOD(5, 6) returns 5, MOD(13,6) returns 1. If there is no modulus the return is 0. With the help of this information you can repetitively count from 0 to 6 and restart with 0.
thank you for taking the time to look at this question.
I'm looking for an equation that can easily take the numerical values from Sheet 1 (the first picture) which has 2 blank cells in between values for four values and then has 4 blank cells and then the other four values. I'm not sure if I am making sense but hopefully the picture I have attached helps.
Notice 2 blank rows between first 4 rows with values (Rows 2-11) and same between rows 16 and 25.
Also notice the 4 blank rows between the two sets of values.
For me, this is repeated for 700 values, same set up of 2 blank rows for 4 sets of values and then 4 blank rows and then four sets of values with 2 blank rows. I'm sure there is an easier way to do this.
I'm trying to recreate Sheet 2 from Sheet 1 using an equation. Is this possible?
Apologies in advance, English isn't my first language.
If the numbers are going to start in B2 and the intervals and offset staggers are static then,
=INDEX(B:B, 2+(ROW(1:1)-1)*3+INT((ROW(1:1)-1)/4)*2)
If the first number is in S6 then,
=INDEX(S:S, 6+(ROW(1:1)-1)*3+INT((ROW(1:1)-1)/4)*2)
Put this in D2:
=IFERROR(INDEX(Sheet1!B:B,AGGREGATE(15,6,ROW(Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A)))/(Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A))<>""),ROW(1:1))),"")
And copy down till you get blanks.
This will return the numbers in order that they appear on sheet 1.
The Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A)) set the data set bounds. This being an array type formula it needs to reference the smallest possible data set. This part finds the last cell in Column A and sets that as the extent of the data set so we do not do unnecessary iterations.
The MATCH part will return the last row that has text in it, if Column A has numbers then we need to change the "ZZZ" to 1E+99 to get the last row in column A with a number.
The AGGREGATE is working like a small in that it will create an array of row numbers and Errors. It will return ROW Numbers where (Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A))<>"") return true. And an Error where it returns FALSE.
The second criterion 6 in Aggregate tells it to ignore the errors, so it is only looking at the returned row numbers.
The ROW(1:1) is a counter. As the formula is dragged down it will iterate to 2 then 3 and so on. This tells the Aggregate that you want the 1st then the 2nd then the 3rd and so on.
The chosen row number is then passed to the INDEX and the correct value is returned.
If your numbers are in order (smallest to largest like your example) or you want the output in order(smallest to largest) then you can use this simple equation in D2:
=IFERROR(SMALL(Sheet1!B:B,ROW(1:1)),"")
Then copy down till you get blanks.
Here is another formula you might use.
=INDIRECT(ADDRESS((INT((ROW()-ROW($A$2))/4)*14+ROW(A$2))+(MOD(ROW()-ROW($A$2),4)*3),COLUMN($A$2),1,1,"Sheet1"))
You can paste it to the first cell where you want the result and copy down.
Note that $A$2 is the cell from where all the counting starts. If your data start from A3 you can change the references accordingly. Note further that ROW($A$2) is long for 2. I chose this syntax to enable you to identify the meaning.
COLUMN($A$2), on the other hand, just identifies Column A as the source of the data to be lifted. Row 2 in this formula is insignificant. It's the A that counts. However, COLUMN($A$2) is long for just 1, meaning column No. 1, meaning A. Once you get your bearing in the formula you can replace COLUMN($A$2) with 1.
I am trying to get year to desired month total of personal expenditure sub categories. After researching stackoverflow, I found a formula seemingly appropriate for my requirements. I found it shifting the desired area by one row down during formula evaluation. I modified the formula by hit and trial on adhoc basis which is giving the correct results. To me the initially chosen formula appeared quite appropriate. I have shown below the sample data sheet and the evaluation steps of the original and modified formula. Could someone explain particularly the offset portion as to why it was going wrong for the initially chosen formula and how the modification helped in solving the problem. Somehow I am not able to get conceptual clarity on this issue.
Sample Data files
Personal_Accounts evaluated with formula A
Personal_Accounts evaluated with modified formula
Offset works by specifying:
A cell from you which you will offset (A1 in this example) then specifying how many rows and columns to move from that position, and then how tall and wide to make the range.
The number of rows to move down: In this case the number of rows down is determined by Match(). Match() here will return the number of rows down in the range A1:A9 that the value SS can be found. The answer is 5. Offset now is looking at Range A1 + 5 rows: A6
The number of columns to move across: Here we move 1 column. No funny business. New range is B6
The number of rows to include in the range from that start point: Here COUNTIFS() is used to return the number of times SS is found in the range A2:A9. The answer is 3. So the range will start at B6 and include three rows down in the range. Essentially B6:B8.
Finally, the number of columns to include in the range: Here it's 7 since that's what you have in cell A13, so your range is now B6:H8
OFfseT() returns that range and Sum sums it up
You subtracted one from the results of MATCH() and correctly moved that formula to produce B5:H7. You could have also changed the search range in MATCH() to A2:A9, which would probably make more sense from a readability standpoint.
Lastly, your COUNTIFS() could just be COUNTIF() since you are not evaluating multiple conditions.
So if I had to write this from scratch, I would use:
=Sum(Offset(A1, Match(A2:A9, A12, 0), 1, Countif(A2:A9, A12), A13)
Which will get you the same correct answer, without any math on Match() results.
Offset has two main functions - either to move to cell (target) using specified number of rows and columns from the starting point, or to select range of specified number of rows and columns starting in the target cell. Your original formula has issue in this part
MATCH(A12;A1:A9;0)
matched cell is fifth therefore the offset moves 5 rows down ending in A6, because it starts in A1 + 5 rows. Then it moves 1 column to be in B6 and then creates range of 3 rows in total and 7 columns = B6:H8. So you need to deduct 1 from the result of the match function to end up in the right row.
For better understanding imagine if the SS value was in the first row of the range A1:A9 (in A1) - then the offset would move from A1 one row down to A2 although you wouldnt want it to move at all.
look at your basic offset formula definition.
Offest (REFERENCE CELL, HOW MANY ROWS TO MOVE FROM REFERENCE, HOW MANY COLUMNS TO MOVE FROM EFERENCE, HOW MANY ROWS TO RETURN, HOW MANY COLUMNS TO RETURN)
so if you set your reference cell to A1 and you want to return the result in A2, you need to move down 1 row from your reference cell.
OFFSET ($A$1,1,0,1,1)
Now if we look at the match portion of your equation, MATCH return what position the information is in. So if we want to find the match position of the information in A2 in a range going from A1:A100, Match is going to tell you that the information in A2 is in the 2nd position of the column. Or more precisely it returns a value of 2.
So now we need to tell offset how far down to reach the 2nd position. We dont actually want it to move down 2 rows to get to the second position since our reference point is A1 which is the first row. As a result we really want to go down 1 row to get to the second row. So you want 1 less from your match results which you correctly did by doing Match(...)-1
I have a design software which extracts data in to an Excel sheet format
The output is divided into 2 columns, each of these columns has more than 1000 rows.
To make use of this data I need to summarize it to a maximum of the 5 highest values from both of the 2 columns. Therefore, this doesn't mean that it's the maximum of one column and its corresponding value, but it may mean that the 2nd largest value of column 1 & the 4th largest value of column 2.
For example ( if we quoted some of the output data):
The values i should pick here are:
If there is any possible way to achieve that, it will be great
Thanks ..
example file: http://goo.gl/UIEFEv
example file 2: http://goo.gl/VSvuVf
Here's a formula solution. I used 20 rows and extracted the rows which contain the top 5 for each column - you can extend to as many rows as required.
With data in A1:B20 use this formula in D1 confirmed with CTRL+SHIFT+ENTER and copied across to E1 and down both columns:
=IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"")
Note: there are only eight rows extracted because some of the rows contain values in the top 5 for both columns. I added the highlighting in colums A and B to more clearly illustrate
see screenshot below
Edit:
From the comments below it seems that you want a combination of rows which contain the highest value for that column....and rows which contain the highest total for both columns.
In the original formula there are two conditions joined with "+", i.e.
($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)
The "+" gives you an "OR" type functionality, e.g. in this case rows are included if individual values are in the top 5 in that particular column. You can add other conditions, so if you want to also add any rows which are in the top 5 considering the total of both columns then you can add another "clause", i.e.
($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)+($A$1:$A$20+$B$1:$B$20>=LARGE($A$1:$A$20+$B$1:$B$20,5))
....and including that in the complete formula you get this version:
=IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5))+($A$1:$A$20+$B$1:$B$20>=LARGE($A$1:$A$20+$B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"")
You could refine that further by using combinations of + and * (for AND), e.g. for the new condition you might only want to include rows with a total in the top 5 if one of the single values is in the top 10 for that column...
Explanation:
The above part shows how you can use + for the OR conditions. In the formula if those conditions are TRUE then the IF function returns the "relative row number" of the range (using ROW(A$1:A$20)-ROW(A$1)+1).
SMALL function then extracts the kth smallest value, k being defined by ROWS(D$1:D1) which starts at 1 in D1 (or E1) and increments by 1 each row.
INDEX function then takes the actual value from that row.
When you run out of qualifying rows SMALL function will return a #NUM! error which IFERROR here converts to a blank
The question is a little unclear but if what you mean is to get the 5 highest values of Column A and their corresponding values in Column B then the five highest values in Column B and the corresponding values in Column A then the (non automated) solution is pretty simple.
Click on a cell with a header title in it.
Click on 'Data' in the top menu.
Click on 'Filter' in the 'Sort & Filter' section.
Click on the button on Column A - select 'Sort Largest to Smallest'
Grab the top five values from both columns then click on the button in column B and repeat.
I would like formulas that count the number of consecutive occurrences in a list of values and places the amount of times it occurs in the next columns.
Here is a spreadsheet I created, it lists the results that Arsenal have achieved so far this season. The values in red are what I would like the formulas to achieve.
https://dl.dropboxusercontent.com/u/92830254/test-sheet.xlsx
I have 3 separate requests:
1) The current run of the team. So if Arsenal won 2 games in a row, then 2 would appear next to each instance of win. Same goes for draw and loss.
2) The current matches that the team has remained unbeaten, i.e. Win or Draw. So if Arsenal had a run like WIN-DRAW-DRAW-WIN, then the 4 would appear in the next column after each of those results. If they lost a game, the column would be blank.
3) Finally, the amount of the matches that the team has scored in, i.e. goals >=1. So if Arsenal's last 3 games were 2,1,1, then 3 would appear after each value in that range. If they failed to score, than it would remain blank.
Thanks.
Still having problems with implementing this, updated 31st October 2014.
I did this in long approach :)
Assuming your data is in Column A with header (meaning actual data starts in A2).
In B2 enter this formula and copy up to where your data extend:
=IF(OR(A2=A3,A1=A2),"YES","NO") 'this checks if consecutive or not
In C2 enter this formula and copy up to where your data extend:
=IF(A2=A1,C1,ROW(A2)) 'this gives identity on numbers that re-occured (eg. 4 in your example)
In D2 enter this formula and copy up to where your data extend:
=COUNTIFS(A:A,A2,B:B,B2,C:C,C2) 'finally, this gives you the values that you want.
Hope this helps you a bit.
Here's the screenshot:
This will do it. It assumes your values are in A2:A11. Note that the range in the formula extends to A12. This is an array formula and needs to be entered with Ctrl-Shift-Enter. Enter it in B2 and copy down:
=IF(A1=A2,B1,MATCH(FALSE,$A2:$A$12=A2,0)-1)
The function you are looking for is countif. It will allow you to count the values in a given range.
Count If Reference