Having A1+C1 and B1+D1 in two cells how can I dynamically set up a formula to catch if some column is added.
Let's say the user adds two columns in the middle. I should have A1+C1+E1 and B1+D1+F1.
I thought it would have been automatic but it is not.
Replace:
=A1+C1
By:
=SUM(A1:C1) - B1
In case you want to check if the column number is divisble by three, you can use following formula:
=IF(MOD(COLUMN(A1);3)=0;A1;0) // I've put the values from 1 to 10 in A1-J1
// and I've dragged this formula from A2 to J2,
// the values were 0,0,3,0,0,6,0,0,9,0.
Unfortunately I don't have a simple way to sum those values in one easy formula.
If you always add two columns then A1+C1 will always be looking at odd number columns and B1+D1 will always be looking at even numbered columns.
{=SUM(IF(ISODD(COLUMN($A$1:$D$1)),$A$1:$D$1))}
and
{=SUM(IF(ISEVEN(COLUMN($A$1:$D$1)),$A$1:$D$1))}
As long as you insert columns between A:D the ranges will extend to accommodate.
Edit:
Based on the comment that row 2 contains codes and row 3 contains the figures to add up for each code then this array formula will work:
{=SUM(IF($A$2:$J$2="H1",$A$3:$J$3))}
Edit2: and if I wake up you can even use the non-array and built in formula:
=SUMIF($A$2:$J$2,"H1",$A$3:$J$3)
The H1 text can be changed to another code or to a cell reference containing the code to get the sum of values in row 3 for the specified code.
As an array formula it must be entered using Ctrl+Shift+Enter.
Related
I need to get a list of unique values from few columns. The data looks like this:
I tried using Unique but it only gives me copy of the list. These 4 lists are already unique values found in another sheet.
If getting unique from 4 columns is impossible, how would I go around combining these 4 columns but instead merging data from a row to 1 cell I'd like to append that one column to have one city per row (so add more rows).
Another idea I had - pulling data from multiple sheets into 1 row, but as it's an automated report, number of towns in each sheet changes every time, so can't use specific cell locations.
You can use the following formula (entered into cell F2 and assuming your data is in range A1:D5)
=IFERROR(LOOKUP("zzzzz",INDEX(IF(COUNTIF(F$1:F1,A$2:D$5),0,A$2:D$5),MIN(IF(COUNTIF(F$1:F1,A$2:D$5),"",ROW(A$2:D$5)-ROW(A$2)+1)),0)),"")
As it is an array formula it needs to be entered using Ctrl+Shift+Enter and copied down until there are blank cells
It does not work in my case, in calc (LibreOffice) that i have exactly the same problem. To extract unique values from multiple columns with text, with blank spaces. I have tried a lot of formulas with no success...
What worked for me - I dont know why this worked for me!
A, B, and C contains text from the 2nd row and onwards. Formula is put on D2 cell as Array formula.
=IFERROR(IFERROR(IFERROR(
INDEX($A$2:$A$20; MATCH(0; COUNTIF($D$1:D1; $A$2:$A$20)+($A$2:$A$20=""); 0));
INDEX($B$2:$B$7; MATCH(0; COUNTIF($D$1:D1; $B$2:$B$7)+($B$2:$B$7=""); 0))
);
INDEX($C$2:$C$12; MATCH(0; COUNTIF($D$1:D1; $C$2:$C$12)+($C$2:$C$12=""); 0))
);
"")
Found here
So, I would like to return the contents of all rows where the value in column A is, let's say, 1.
My thought process is that I could use:
=INDEX(row_range,MATCH(1,A:A,0),0))
But Match will only return one value here, i.e. the number of the first row which contains a 1 in column A.
Is there a way of creating an array with the Match formula (thus returning the multiple row numbers, all of which contain '1' in column A) and then place that in the Index array so that it then runs through each of the Match-array values and creates a big long list of values in one array which I can then list out on a separate sheet?
Hope this makes sense...
Here is a demonstration of what I'm hoping for, if that helps! The idea would be that the array as shown would be created, which could then be extended down the column as per the part underneath.
https://i.stack.imgur.com/nCusM.png
Use the file you showed in your example (as "Sheet1") and put these formulas into indicated cells in Sheet2:
Into cell A2 put
=AGGREGATE(15;6;ROW(Sheet1!A:A)/((Sheet1!A:A=1)*1);ROW(A1))
this will give you all the rownumbers where value in A column of sheet1 equals 1.
Into cell B2 put
=COUNTA(INDIRECT("Sheet1!"&A2&":"&A2))-1
this will give you how many cells are filled in that row.
Into cell C2 put
=TEXTJOIN(",";TRUE;OFFSET(Sheet1!$A$1;A2-1;1;1;B2))
This will give you all the cells with data from that row concatenated. If you dont have this formula (first time in 2016 I believe) you can use OFFSET function to list the values in separate columns and then CONCATENATE them.
Copy these three down as many times as you want and into cell C1 put
=TEXTJOIN(",";TRUE;OFFSET(C2;0;0;COUNTIF(Sheet1!A:A;1);1))
So this seems like it should be pretty easy. I could just concatenate and make another column in the data to make a unique combo and get my answer. But that just seems so messy. So here I am reaching out to you fine folks to pick your brains.
I want to look up HQLine and Description in the MPCC tab to return the correct MPCC Code. I tried a couple IF statements with VLOOKUPS but couldn't get it right.
So I need to look up BK3 Positive Crankcase Ventilation (PCV) Connector in the MPCC tab. So it needs to match BK3 and the Long description and then give me the correct code.
Here is the missing data file
Here is the MPCC export list that I want to search
Use SUMIFS.
SUMIFS will find the sum in a table of rows that meet certain criteria. If the MPCC is always a number, and the MQAb-LongDescription is always unique, SUMIFS will find the correct ID.
=SUMIFS(Sheet1!C$2:C$100,Sheet1!A$2:A$100,A2,Sheet1!B$2:B$100,B2)
where Sheet1!A$2:A$100 is the HQAb data, Sheet1!B$2:B$100 is the Long Description data, Sheet1!C$2:C$100 is the MPCC Number data, A2 is the HQLine, and B2 is the Description.
The formula would go in C1.
More information on VLookup with Multiple Criteria
You can use an Index/Match with multiple criteria.
I'm assuming that you will put this formula in "Sheet1", cell C2, and your lookup data is in a sheet called "Sheet2", columns A, B, C from row 2 to 30.
Put this in Sheet1, C2:
=INDEX(Sheet2!$C$2:$C$30,MATCH(A2&B2,Sheet2!$A$2:$A$30&Sheet2!$B$2:$B$30,0))
(Enter with CTRL+SHIFT+ENTER) and drag down.)
Adjust the ranges as necessary.
lets assume your first Table is on sheet 1 in the range A1:C11 and the MPCC codes are located on Sheet 2 in the range A1:C32. Each table has a header row so your data really starts in row 2.
Similar to BruceWayne's answer of using an array formula, you can bring the array calculation inside of a formula and avoid the special array treatment. There are a few functions that can do this. I will demonstrate with the SUMPRODUCT function;
On Sheet 1, Cell C2, use the following formula:
=INDEX('Sheet 2'!$C$1:C$32,SUMPRODUCT((A2='Sheet 2'!$A$2:A$32)*(B2='Sheet 2'!$B$2:B$32)*row('Sheet 2'!$A$2:A$32))
Explanation:
When the value in A2 matches the value in the range in the second sheet it will be true and false when it does not. when True False get used in math operations they are treated at 1 and 0 respectively. Therefore the only result from your two search criteria will be the rows where A2 match is true and B2 match is true and this will have a value of 1. The 1 will then be multiplied by the row number. Since all other results will be 0 since your list is a unique combination, the sum part of sumproduct will sum up to the row number where your unique row is located. This in turn is used by the indext function to return the row to give your unique number.
Let's say,
Sheet1:A1 = x
Sheet2 contents look like
x 3 3 4
y 0 2 1
Is there an excel formula that could match Sheet1:A1 with Sheet2:A1 (basically the value 'x') and add the other cells in that row (3,3,4). The result (Sum='10') should get updated at Sheet1:C4 lets say.
I tried SUMIF but that shows the content of only one column due to the restriction that it can handle only the matchable array size. I know this can be achieved through VBA, but just wanted to know if a formula is available.
TIA!
This formula will do what you want:
=SUM(SUMIF(Sheet2!A:A,A1,INDIRECT("Sheet2!" & {"B:B","C:C","D:D"})))
It will iterate through the columns doing individual SUMIF() on each and then adding the results.
If you want more columns or different change the address in the array to the columns desired.
Try the following
=SUM(IF(Sheet2!A1:A99=A1,Sheet2!B1:D99,0))
Note that this is an array formula, so it must be entered using Ctrl+Shift+Enter.
What this formula does is converts any rows on Sheet2 without x in column A to zeros in B:D and then sums what is left.
Similarly, you could use
=SUMPRODUCT((Sheet2!A1:A99=A1)*Sheet2!B1:D99)
and you wouldn't have to enter it as an array formula.
For a non-volatile, non-array formula, try this
=SUM(INDEX(Sheet2!B:D,MATCH(Sheet1!A1,Sheet2!A:A,0),))
I am trying to display the total sum of all the numbers for a particular column. I want the sum to be displayed above the column as follows:
21 30
A B
6 5
6 10
6 10
3 5
I know I can sum the values and display it at the bottom of the column using =SUM(A3:INDIRECT("D"&ROW()-2)), however I am not getting a way to display it at the top of the column.
Please guide.
Based on the comments and the previous answers I suggest following formula, entered in cell A1:
=SUM(OFFSET(A$2,0,0,ROWS(b:b)-1))
You can then copy/paste to the right till second last column.
You could also modify your formula in A1 like this to achieve the same:
=SUM(INDIRECT("A2:A"&ROWS(A:A)-2))
But then you cannot copy/paste to the right...
A more general approach with your idea would be:
=SUM(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROWS(A:A),COLUMN())))
You can then copy/paste to the right till last column.
Some explanations:
Both formula sums up every value in the range from A2 till the bottom of column A (i.e. for Excel 2010 this would be A2:A1048576)
It doesn't matter if there are blanks or cells without value; the formula sums up only the numbers
I put A$2 and B:B in the OFFSET formula to avoid circular references, since I'm writing in cell A1 and I cannot write A$1 nor A:A
With the INDIRECT formula you don't have to worry about circular references
Further commenting (sorry, I don't have the credits to comment at the right place under the question):
Phylogenesis formula =SUM(A3:A65535) could also do the work, isn't it?
Didn't understand your question at first, because you talk of "sum of all the numbers for a particular row" but then you sum columns, isn't it?
When I'm doing something like this, I prefer to not include any empty cells beneath the range I'm summing, because I've had errors in the past as the result of including them (usually because there's a cell way down in the column somewhere that I'm not expecting to have a value). I'm assuming that A & B are your column headers. Assuming that, here is how I would do it. This is your formula for cell A1:
=SUM(OFFSET(A$1,2,0,COUNTA(A$3:A$65535)))
Explanation
I'm updating this with a brief explanation, per the OP's request.
According to ExcelFunctions.net:
The Excel Offset function returns range of cells that is a specified number of rows and columns from an initial supplied range.
The function reference for OFFSET is:
=OFFSET(reference, rows, cols, [height], [width])
What this formula does is create a dynamic range based on the number of cells in the selection, relative to cell A$1. This is an offset of two rows and no columns, which starts the range at A$3. The height of the range is the total number of filled cells in the range A$3:A$65535. The assumption here is that there are no blank cells in the range, which there were not in the sample data.