I have the following data in excel / google spreadsheet,column A contains values separated by a, and this column will be updated everyday with new data. Column B shows the sum for all values separated by a's. For instance, there are two values between the 1st a and 2nd a, therefore the sum for these two = 2+2=4. There are three values between the 2nd a and the 3rd a, therefore the sum for these three = 3+2+4=9.
I am just wondering if I could write a function in column B to automatically detect where a is and then do the sum for all future data. It's like doing the loop thing in programming.
Any advice would be greatly appreciated.
Assuming you never have more than 100 rows of numbers between "a" the following formula works =IF(A9="a",SUM(OFFSET(A10,0,0,IFERROR(MATCH("a",A10:A107,0),100)-1,1)),"")` in cell B3
Related
Struggling a bit with array formula's to count distinct values in one column, in the rows where two other cells match. Sorry if I can't explain any better. Best is to show you the formula I created and provide some sample data:
Sheet 1
Column A Column B
Period 101 Code X
Period 309 Code Y
Period 101 Code Y
Period 101 Code Z
Period 404 Code Y
Period 101 Code X
Period 101 Code X
Period 404 Code X
Period 404 Code Z
Sheet 2
Column A Column B (where the formula should be)
Code X 2
Code Y 3
Code Z 2
Basically I want to count the distinct values in Sheet 1 column A, only where the value in Sheet 1 column B matches the value in sheet 2 column A. I have provided the expected outcome for the three code values.
I have tried with the following formula, but I am unable to count distinct values in another column where the two cells match:
{=SUM(--(FREQUENCY(IF(C5:C11=G5,MATCH(B5:B11,B5:B11,0)),ROW(B5:B11)-ROW(B5)+1)>0))}
Please ignore the rows and columns used in the formula, also the values in Column A and B on sheet 1 both occur multiple times, but the values in column one on sheet 2 only occur once.
I am curious how someone would solve this one. Thank you in advance.
Caveat: This answer is unlikely to be useful to the OP, as these techniques are as yet only available to Excel Insiders
But once these new features are available to the main stream they will be a game changer.
This uses the new Dynamic Array feature coming to Excel soon.
To create the list of unique values from Column B, place this formula in a single cell. Excel will "Spill" into as many rows as needed to return the unique list of values from Column B. For example, I have used cell E2
=UNIQUE(FILTER($B:$B,$B:$B<>""))
Now, place this formula in a the next adjacent cell, I've used F2
=COUNTA(UNIQUE(FILTER($A:$A,$B:$B=$E$2)))
Again, you only need to put this formula in one cell, no need to copy down. Excel will "Spill" the result into as many cells as needed, to match column E.
Your formula doesn't match your sample data but let's assume the below:
Formula in H5:
=SUM(--(FREQUENCY(IF(C$5:C$13=G5,MATCH(B$5:B$13,B$5:B$13,0)),ROW(B$5:B$13)-ROW(B$5)+1)>0))
Entered as array through CtrlShiftEnter and drag down
Notice the semi-absolute cell references (you used relative ones) + how my ranges are larger than yours (you looked from C5:C11 only)
My spreadsheet has a list of names (some are repeated) in column A, a list of numbers stored in a string in column B, and column C uses a formula to get the first number of the string in column B. In column E have created a list of the unique names from column A, in column F a number of times they appear in the data list and in column G i then want to fetch the corresponding number data from column C each time it appears in the list to calculate average numbers.
I have tried this
=SUMPRODUCT(($A$1:INDEX($A:$A,COUNTA($A:$A))=$E4)*($C$2:INDEX($C:$C,COUNTA($C:$C))))/$F4
The problem i have is that in the list of data some of the cells in column C are blank so i am getting a #VALUE error.
Here is a screenshot of what i am trying:
Is there anyway to tell SUMPRODUCT to skip the rows where there is no number data?
Obviously this is just an example and my actual spreadsheet is a little more complicated, there are thousands of rows of data and the names are repeated many times over.
Empty cells are not your problem. It would just be accepted in a formula like yours. Unfortunately the problem is because you have gaps, COUNTA will return a range that's not equal to column A > COUNTA in column A will return 15, whereas COUNTA in column C will return 11. Unequal ranges will return #VALUE
In this specific case your issue is resolved through:
=SUMPRODUCT(($A$1:INDEX($A:$A,COUNTA($A:$A))=$E4)*($C$1:INDEX($C:$C,COUNTA($A:$A))))/$F4
In G4, copied down :
=SUMIF($A:$A,$E4,$C:$C)/$F4
Edit : SUMIF() can use whole column reference of which bounded on used range only, and can avoid to use dynamic range.
I have two sheets in Excel, Sheet1 and Sheet2.
They both contain 3 columns A, B and C.
My goal is to get values from C in Sheet2 to C in Sheet1, based on conditions comparing the values in both A and B at the same time.
A in Sheet2 contains numbers grouped together, for example 11,11,13,13,12,12. A in Sheeet1 contains some of those numbers, but not nessecarily in the same order or the same number of rows, for example 11,11,12,13,13.
B in Sheet2 also contains numbers like 2,1,1,2,1,2. B in Sheet1 again contains part of those numbers. For example, 1,2,1,1,2.
There are only unique combinations of pairs in A and B (in that specific order) for Sheet1 and Sheet2 respectively.
C in Sheet2 consists of numbers connected to the specific combination of numbers in A and B.
Now, I want to fill C in Sheet1 based on the values from C in Sheet2. For example for C1: Get the value (row x) in 'Sheet2'!Cx, so that 'Sheet1'!A1='Sheet2'!Ax, AND 'Sheet1'!B1='Sheet2'!Bx (which would be the 2nd row in this example).
I was thinking about something like
C1=INDEX('Sheet2'!C:C;...)
where
...=IF(AND(MATCH(A1;'Sheet2'!A:A;0);MATCH(B1;'Sheet2'!B:B;0));?;?)
?= I don't know what I would write here, but I would want the return value of IF be the row number where both conditions are true.
The problem is that MATCH only returns the first number in A and B respectively for which the condition is true, while I have several non-unique numbers in A. I would want to look through the whole 'Sheet2'!A:A and get all the matching values, and then look through the corresponding 'Sheet2'!B:B to check the second condition.
Or there might be a completely different take on this problem. Do someone have a suggestion on how to solve this?
Here is a way to look at multiple values in a MATCH() function, example:
Sheet1:
Sheet2:
Formula in C2 sheet1:
{=IFERROR(INDEX(Sheet2!$C$2:$C$6,MATCH(Sheet1!A2&Sheet1!B2,Sheet2!$A$2:$A$6&Sheet2!$B$2:$B$6,0)),"")}
Note: It's an array formula so enter through CtrlShiftEnter
Result:
C1 Formula =INDEX(Sheet2!C:C;MATCH(A1;Sheet2!A:A;0);MATCH(B1;Sheet2!B:B;0))
I have excel sheet with 500 rows and more than 10 columns. The first column is subject id.
And I have list of subject id approximately contains 2000 id. The 500 id in the spreadsheet is subset of the external 2000 id.
I want to arrange the spreadsheet rows according to the external list of ids.
Edit:
I have spreadsheet 'A' of 500 rows
and spreadsheet 'B' with 5000 rows
I want to edit spreadsheet 'A' by place its rows at the same position (row number) of its occurrence in 'B'.
In other words, you can see from above pictures that:
First subject of 'A' '2196978' is located in row number 2 in 'B'. My task is to put '2196978' of 'A' in row number 2
Second subject of 'A' '2219364' is located in row number 9 in 'B'. My task is to put '2219364' of 'A' in row number 9
and this is done by insert rows in 'A' if the subject of 'B' is not exist in 'A'.
This result is what I want:
Without resorting to Macros I don't think what you want to achieve is possible, however it is possible to get something very close. The core issue is that a function cannot create rows so you have to start with the number you want to end up with.
I my proposal you end up with a 3 Book solution. Book A with 500 rows, Book B with 2,000 rows, and Book C which is the result also with 2,000 rows but many of them blank.
You would start by creating Book C with a complete list of IDs from Book B i.e. all 2,000 of them. This could be a copy and paste or you could assign them using the Excel = function. For this example put them into column "A".
Next we want data to appear only if it is in Book A. We do the lookup using VLOOKUP() and if the data is missing we get a #N/A error.
So before things get complex in column B of the new Book add the formula:
=IF(ISNA(VLOOKUP(A1,[BookA]Sheet1!$A$1:$A$200,1,FALSE)),"row missing","row there")
This will return a text message indicating if the row exists in Book A and will be used as a flag to display the remainder of the data.
Check this works and if it does change it to:
=IF(ISNA(VLOOKUP(A1,[BookA]Sheet1!$A$1:$A$200,1,FALSE)),FALSE,TRUE)
We now want to get column B, C, D etc. from Book A based upon the True/False flag we have created. So column C in the new sheet is something like:
=IF($B1,[BookA]Sheet1!B1,"")
If you have the $ signs in the right places is should copy and paste nicely.
You have 2 options for improving this and getting nearer your objective.
Embed the initial lookup in the 2nd IF statement
Use conditional formatting to turn the text white if it should not be there (including the ID)
I have not done either of these because it is un-readable and is basically write once code that you can never modify without starting again.
Good luck.
You have to use the below formula in spreadsheet B which contains 5000 rows,
=IFERROR(INDEX(SheetA!$A:$J,MATCH($A2,SheetA!$A:$A,0),COLUMN()),"")
This is a simple INDEX - MATCH formula which looks up values in SheetA matches it with SheetB and prints output in SheetB. Use the formula in SheetB cell B2.
Explanation:
A2 cell in SheetB is matched with A:A in SheetA.
If found, pulls all the column data of that item from A:J from SheetA.
Once you pasted the formula in B2, drag it across all required columns. Then drag the same across all rows or just double click the fill handle, so that the formula is filled for all 5000 rows and data is pulled.
Let me know if you face any difficulties. Hope this helps.
I have 2 sets of data. I put it in Excel e.g. column A and column B. Now I want to know which data from B is part of column A. I run this formula =IF(COUNTIF($A$1:$A$327238,B1)>0,"Exist", "Nope")
Then I 'filter it and look only 'Exist'. Based on that I know that all data in B that has label 'Exist' is part of column A
Now I want to know opposite i.e. which data from A are part of B. For that reason I use the same formula but I replace the data in columns i.e. data from B now in A and vice versa.
Then I randomly verify results.
For case 1 it looks it works fine but for second case it looks it's not accurate.
My assumption: should it work in case 2 as well ( maybe I just was not very accurate in some way ) and I should expect it to work?
Thanks
In cell C1 (assuming your data starts from 1st row) type the following =IF(A2=B2,"equal","no"), and then populate the same formula to the last row where there is still data, so that for row N, your formula in column C is =IF(AN=BN,"equal","no"). After that you will just need to count the cells with value "no" to know the differences. Sorry if I didn't get the question correctly.
Ok, assuming that the two sets of data are in columns A and B (they might be of different sizes), and the last rows of data are L and M respectively, click on D1 and type the following: =IFNA(INDEX(B$1:B$5,MATCH(A1,B$1:B$5,0),1),"Unique"). Drag down to apply this formula on D1 - DL. That's it, you have the duplicate elements. Since the duplicate elements are the same in both columns - A and B, you don't need to repeat this for column B. Note, that for all the unique elements the corresponding rows of column D have the word "Unique", so if you want the unique elements, you can just get the elements from A with the mentioned row numbers:
Just select any column's first row cell and type the following formula: =IF(D1="Unique",INDEX(A$1:A$L,ROW(D1)),"Duplicate").