How to sort table using function/equation only - excel
How can I sort a table in sheet 1 like
A B C D E
3 7 3 6 5
into another table in sheet 2
A C E D B
3 3 5 6 7
by using function only?
One really easy way to do it would be to just have a rank index and then use HLOOKUP to find the corresponding values:
=RANK(A4,$A$4:$E$4,1)
=IF(COUNTIF($A$1:A$1,A1)>1,RANK(A4,$A$4:$E$4,1)+COUNTIF($A$1:A$1,A1)-1,RANK(A4,$A$4:$E$4,1))
=HLOOKUP(COLUMN(),$A$2:$E$4,2,FALSE)
=HLOOKUP(COLUMN(),$A$2:$E$4,3,FALSE)
Okay, here's the "one formula does it all" solution without additional temporary columns:
Formula in A6:
=INDEX($A$2:$E$2,MATCH(SMALL($A$3:$E$3+COLUMN($A$3:$E$3)/100000000,COLUMN()),$A$3:$E$3+COLUMN($A$3:$E$3)/100000000,0))
Enter it as an array formula, i.e. press Ctrl-Shift-Enter. Then copy it to the adjacent columns.
To get also the number, use this formula in A7 (again as array formula):
=ROUND(SMALL($A$3:$E$3+COLUMN($A$3:$E$3)/100000000,COLUMN()),6)
Both formulas are a bit bloated as they have to also handle the potential duplicates. The solution is to simply add a very tiny fraction of the column before applying the sorting (SMALL function) - and then to remove it again...
I think an easier solution is to use the "Large" function:
The Column functions are just an easy way to count from 5 down to 1, but a helper column may be even easier.
You can have a similar answer using the "Small" function as well.
Although I have used the "add a small number technique", I think this is the most elegant for a helper row/column:
=RANK(B4,$B$4:$F$4,0) + COUNTIF($B$4:$F$4,B4)-1
(copy across the row column) RANK gets you close and the COUNTIF portion handles duplicates by counting the number of duplicates of the cell to that point. Since there is always match (itself) you subtract 1 for the final rank. This "sorts" ties in the order that they appear. Note that an empty cell will generate #N/A and character data as #Values.
It's doable! :-)
Here is the sample file.
Explanation
I assume that your data is in row 1 of Sheet1 and that you want the data sorted starting in column 1 of another sheet - if not, adjust accordingly.
Place this formula in column 1 of the target sheet, say in row 2:
=ROUND(SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),6)
You need to enter the formula as an array formula, i.e. press Ctrl-Shift-Enter.
In case you place it in another column than column one, you need to replace COLUMN() with COLUMN()-COLUMN($A$2)+1 where $A$2must be a reference to the cell itself.
This formula will return you the lowest number in your range - if you copy it the next 4 columns, you'll get your order list of numbers.
To translate this back to the column number, we need to perform 2 steps:
Figure out the column number:This can be done with with this formula:
=MATCH(SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,0)
- again, to be entered as array formula. If the source data does not start in column A, you need to add +COLUMN(Sheet1!$A$1)-1 where $A$1 needs to be replaced with the leftmost cell of the source data.
Convert the column number to a letter:Assuming your column number from step 1 is in cell A6, this formula will do the job:
=LEFT(ADDRESS(1,A6,2),SEARCH("$",ADDRESS(1,A6,2))-1)
Of course, you can also combine step 1&2, this will result in this megaformula:
=LEFT(
ADDRESS(
1,
MATCH(
SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),
Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,
0),
2),
SEARCH(
"$",
ADDRESS(
1,
MATCH(
SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),
Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,0),
2)
)-1
)
Again, to be entered as array formula.
Related
Using INDEX MATCH function to multiply and sum rows
I've the following table: In cell A7 I define the index of column 1 I want to use for my computation, in this case A. For every row with index A I want to multiple the value for that row of column 2 with column 3. In this example there are two rows with index A, so I want to do the computation for both rows and then add the results. That will look as follows: 5 * 3 + 9 * 7= 78. To achieve this, I first tried to write a code that sums all values in column 2 that match a given index. That index is A, so 5 + 9= 14 is what the output should be. I only get my code to find the first match, so that's row 2 and it will display the value of column 2, so that's 5. This is my code for cell B7: =SUM(INDEX(B2:B5;MATCH(A7;A2:A5;0))) Even if I solve this I still don't have what I actually want, but I think it's a start. How do I get what I innitially wanted and have the outcome equal 78?
Type in this formula: =SUM((A2:A5=A7)*(B2:B5)*(C2:C5)) Then Ctrl-Shift-Enter This converts it into an array formula, which you can identify because there will be braces around it: {=SUM((A2:A5=A7)*(B2:B5)*(C2:C5))}
Using BYROW() • Formula used in cell B7 =SUM(BYROW(FILTER(Table12[[Column 2]:[Column 3]],A7=Table12[Column 1]),LAMBDA(m,PRODUCT(m)))) If not using Structured References then =SUM(BYROW(FILTER(B2:C5,A7=A2:A5),LAMBDA(m,PRODUCT(m)))) Or, use the incredible & versatile SUMPRODUCT() Function • Formula used in cell C7 =SUMPRODUCT((A7=A2:A5)*(B2:B5)*(C2:C5))
Countif or sumif function in Excel
I have 2 tables, one which gets populated with results (on the right) and the other is the summary of that results table (on the left). Not even sure if countif is the correct approach but I just wondered if there was a formula I can put into B2:D3 which can add up the number of occurences in the results table. So going forward I'll just need to manually insert another row in columns I and J which would update B2:D3
Use this as shown in image below, going forward when you add more values in column I & J, it shall give you the number of occurrences of L, W, & D respectively as per Name Enter the formula in cell B2 & Fill Down -- Fill Right =SUMPRODUCT(($A2=$I$1:$J$1)*(B$1=$I:$J)) What this formula does is creates an array of TRUE's & FALSE's, select the Array 1 & Press F9, ($A2=$I$1:$J$1) {TRUE,FALSE} likewise for the Array 2 as well (B$1=$I:$J) {FALSE,FALSE;TRUE,TRUE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,FALSE;FALSE,) Each Array 1 will be multiplied by corresponding Array 2 and returns the sum of the products, by far this is safest option and can be used in all Excel Versions.
You can add the following formula into B2: =COUNTIF($H$2:$H$3,B$1) It will count all 'W' occurrences in the H2:H3 range. You can drag this formula to the right. For the B3 cell, you need to update the column from H to I.
Sum column based on conditions for subsums
So I have a table which basically looks as follows: Criterion Value 1 -5 1 1 2 5 2 5 3 2 3 -1 I want to sum the values in column B based on the criteria in column A, but only if the sum for an individual criterion is not negative. So for example if I ask for the sum of all values where criterion is between 1 and 3, the result should be 11 (the values for criterion 1 not being included in the sum because they add up to a negative number. My first idea was to add a third column with a sumif([criterion];[#criterion];[value]) and then use a sumifs function which checks whether that that third column is negative. However, my table has +100k lines and with that many sumif functions it becomes intolerably slow. I know I could create a pivot table to the same effect, but that has two drawbacks: I would have to create a separate sheet, which would add complexity, and my table is frequently updated which means I would have to manually update that pivot table every time to allow for downstream calculations. NBD and I could do that as a last resort, but I wonder whether there isn't a more elegant way to solve this problem. I would want to avoid VBA to avoid complexity (the sheet will be used by other persons). Thank you
This can be easily done using UNIQUE() and the two versions of SUMIF() in this way: First collect all the criteria with =UNIQUE(A2:A7) -- Assuming your data are in columns A and B starting from row 2, this goes in cell C2, with "Criteria" in C1 Compute the subtotals for all criteria using =SUMIF($A$2:$A$7, C2, $B$2:$B$7) -- This goes in cell D2 and extends as the criteria do, "Partials" in cell D1 sum all the data in step 2 yielding a positive sum with =SUMIF(D2:D7, ">0") in cell E2 If you have a lot of data I suggest to use the column references to avoid absolute references and the need to adjust the formulas as data change (in number): The first formula becomes =UNIQUE(A:A) -- Don't care about the heading being taken (strings and empty cells are not summed) For the second formula use =SUMIF(A:A, C2, B:B) Use =SUMIF(D:D, ">0") for the last step This should be reasonably fast, using just as many extra cells as the number of distinct criteria (multiplied by 2).
Match and move the columns in Excel
Hi; I have a sheet which has 4 columns ; Column A and C have product numbers Column B and D are for detail of the products. What i'm trying to do is ; If a number in column A match with a number in column C then i want to take the value (product details) of B to column E. but if the number repeats then at second row and match again with that number in column C then i want to that the new value to column F. It's a really particular problem for us. We are trying to create a new sql database for our new web page and we have to convert all data like this. I tried it with =vlookup formula in Excel but it didn't work. i think this problem can solve only with macros. (If i'm not wrong...) PS_ Please check the image, it's even hard to explain in my mother language. Thanks
If you have less than 2000-3000 rows of data, this can be accomplished with some array formulas. If you have much more than that, a VBA solution would be better suited. These array formulas eat up calculation load exponentially as the ranges they refer to grow larger. At some point it simply isn't worth waiting for and a VBA solution would be better. The array formula in F2 is, =IF(LEN(F1), IFERROR(INDEX(A$1:A$999, MATCH(0, IF(LEN(A$1:A$999), COUNTIF(F$1:F1, A$1:A$999&""), 1), 0)), IFERROR(INDEX(C$1:C$999, MATCH(0, IF(LEN(C$1:C$999), COUNTIF(F$1:F1, C$1:C$999&""), 1), 0)), "")), "") Note that this requires a header column label in F1. It cannot be put into F1. Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered correctly, fill down to pick up a unique list of all the part numbers from columns A and C. The array formula in G2 is, =IF(LEN($F2), IFERROR(INDEX($B$1:$B$999, MATCH(0, IF($A$1:$A$999=$F2, COUNTIF($F2:F2, $B$1:$B$999&""), 1), 0)), IFERROR(INDEX($D$1:$D$999, MATCH(0, IF($C$1:$C$999=$F2, COUNTIF($F2:F2, $D$1:$D$999&""), 1), 0)), "")), "") This also requires finalizing with Ctrl+Shift+Enter↵. Once entered correctly, fill right several columns and then fill all of the formula down to match the entries retrieved in column F. I've left those formulas to cover 999 rows. You may need to adjust those upwards if your needs exceed that range. A search for $999 and replace with $1999 can quickly accomplish that. That is all there is to it. Make sure you leave a few rows at the bottom in case another file has more rows and a few columns to the right for teh same reason.
If the order is not critical, a possible alternative with formulae only would be to append the second two columns to the first two (in a copy), add a blank Row1 and in ColumnC: =IF(COLUMN()<=COUNTIF($A:$A,$A2)+2,INDIRECT("$B"&(COLUMN()-3+ROW())),"") copied across and down to suit and in another column: =A1=A2 copied down to suit. Hide ColumnB and filter the other column to select FALSE. Select Row2 to end and Paste Special, Values into F1 of original sheet.
Excel: Multiply each cell in row X by corresponding cell in row 2, and get sum
I have a table set up as follows: Column 1 - Customer Name Row 1 - Item Name Row 2 - Item Cost Row 3+- Item Quantity How do I set up the last column to calculate the total cost for each customer? I.e, For each customer row, I want to multiply the number in each cell (= quantity) by the corresponding cell in Row 2 (= cost), and add them all up for the final bill. To clarify what I'm saying I'm attaching the following picture so that we can discuss specifics.
Have you tried SUMPRODUCT - it does exactly what you need, gives the sum of 2 or more multiplied ranges? =SUMPRODUCT(A71:C71,$A$2:$C$2) You can extend the ranges as far as you need. If you want to add columns make sure you don't add at the end, e.g. if you retain one blank column (D currently) and include that in the formula, then if you add a column at D the formula will automatically extend to E
You can use sumproduct but specify the ranges, e.g. =sumproduct(B2:B6,C2:C6), the next row would then be =sumproduct(B2:B6,D2:D6) etc. I'm sure there's a way to "fix" your cost row but it's quite quick doing it this way
If, for example, your first data set is in column A (i.e. per unit cost) and the second data set is in column B (i.e. quantity), and you want the total cost for each item for the specified quantity, place the following formula in C1 =A1*B1 Select C1 and drag the fill handle - this is the small black square at the bottom right corner of the cursor as far down the column as you need. The program will automatically replicate the formula with the correct cell numbers for each row.
One way is to use this formula: =SUM(B4:B5)*B2+SUM(C4:C5)*C2 It is not so cool but you still need to expand the formula even with SUMPRODUCT because the range has to be the same as far as I know. The other way I came up will use a matrix function called MMULT and here is the example: With this array (means you have to click Ctrl + Shift + Enter altogether) formula entered into cell D6: =SUM(MMULT(B2:C2,TRANSPOSE(B3:C5))), you will get your expected result without needing all the subtotals. Please note this is a 2 x 1 By 2 x 3 Matrixformula.