I have two tables and I have to calculate the values based on join conditions. Is it possible to do it with formulas?
The tables are like follows
Table1
RefT1 Value
A 7
B 2
C 5
D 4
Table2
RefT2 Value
B 5
D 8
E 7
I need to calculate:
The sum of values of items in both tables
The sum of the values in Table1 but not on Table2
The sum of the values in Table2 but not on Table1
What formula can I use to achieve this?
You will need three formulas
Both(an Array Formula):
=SUM(SUMIF(A2:A5,D2:D4,B2:B5),SUMIF(D2:D4,A2:A5,E2:E4))
Enter with Ctrl-Shift-Enter
table 1:
=SUMPRODUCT(--(ISERROR(MATCH(A2:A5,D2:D4,0))),B2:B5)
Table 2: reverse the columns:
=SUMPRODUCT(--(ISERROR(MATCH(D2:D4,A2:A5,0))),E2:E4)
Assuming that you have to ListObjects / tables with the names Table1 and Table2 and the column names you have used in your example the following formula will give you the sum of items found in Table1 (which exist also in Table2):
=SUM(IF(ISERROR(MATCH(Table1[RefT1],Table2[RefT2],0)),0,Table1[Value]))
In inverse thereof gives you the sum for all items in Table2 (which exist also in Table1):
=SUM(IF(ISERROR(MATCH(Table2[RefT2],Table1[RefT1],0)),0,Table2[Value]))
Of course, the sum of both should be the "joining" sum of items:
Note, that all formulas are array formulas and as such must be entered using Ctrl + Shift + Enter. For more information on array formulas read this: https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7D94A64E-3FF3-4686-9372-ECFD5CAA57C7
Related
I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)
I have an excel table that looks like this
Row Column1 Column2 Column3
R1 A B C
R2 C D X
I have a table that holds the values corresponding to the entries in Columns 1 to 3 which looks like this -
Key Value
A 1
B 7
C 2
D 4
X 9
I want to create a Column4 that has the maximum looked-up value of columns 1 to 3, i.e. the result would look like this -
Row Column1 Column2 Column3 Looked_Up_Max
R1 A B C 7
R2 C D X 9
I tried writing an array formula like this -
={max(if(B1:D1,vlookup(B1:D1,lookup_table!$A$1:$B$5,2,0)))}
But it does not work. Any way to do this is one step instead of say creating three additional columns with the looked up values and then taking a max of the additional columns?
Thank you for the help
If the data on the lookup table is sorted then you can use this array formula:
=MAX(LOOKUP(B2:D2,$H$2:$H$5,$I$2:$I$5))
Being an array it needs to be confirmed with Ctrl-Shift-enter instead of Enter when exiting edit mode.
Another that does not care about sort order that uses SUMIFS()
=MAX(SUMIFS(I:I,H:H,B2:D2))
Still an array formula, but this assumes that the Key in the lookup is unique.
If not in order and not unique and the user wants the first then we need this convoluted array formula:
=MAX(IFERROR(INDEX(I:I,N(IF({1},MATCH(B2:D2,H:H,0)))),-1E+99))
Still and Array formula.
I have a table of data that include a name column and two numeric columns. Example:
A B C
Fred 4 2
Sam 3 6
George 1 7
I'm wanting to retrieve the name in column A for the largest sum of columns B and C. In the example above, I would want "Sam" because 3+6 is greater than any of the other sums.
I know I could create a hidden column (D) that's filed with
=SUM(B2,C2)
and do something like this:
=INDEX(A:A,MATCH(MAX(D:D),D:D,0))
but I'd rather avoid the hidden column, if possible. Is there a way to perform an index-match based on the sum of two cells?
Use the array formula:
=INDEX(A:A,MATCH(MAX((B:B)+(C:C)),(B:B)+(C:C),0))
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
(Note the appearance of braces in the formula bar)
I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)
Table1
A B C D
1 Seq Item Re-Order Qty On-hand Qty
2 1 X 10 15
3 2 Y 10 5
4 3 Z 10 10
Other worksheet:
Table2
Expected output:
A B C
1 Seq Item Re-Order Qty
2 1 N/A N/A
3 2 Y 10
4 3 N/A N/A
In table2 I need to put in column 2 equation like this:
Index(Table1[Item],Match(table2[Seq],tabel1[Seq],0) WHERE table1[reorder qty] > table1[On-hand Qty]
I'm not sure how such requirement could be managed?
This can be done. It requires the use of an array formula in Table2.
Normally with an INDEX you simply use a range of cells as the array (first argument of the formula). In this case, we will give it a new array to return based on the results of a conditional (your WHERE clause).
I will start with the picture of results and then give the formulas. For me, Table1 is on the left, Table2 on the right.
Formulas
The formulas are very similar, the main difference is which column to return in the IF part which generates the array for INDEX. The conditional part of the IF is the same for all columns. Note that using Tables here really helps copying around the formulas since the ranges cannot change under us.
These are all array formulas and need to be entered with CTRL+SHIFT+ENTER.
Table2[Item]
=INDEX(IF(Table1[Re-Order Qty]>Table1[On-hand Qty],Table1[Item],"N/A"), MATCH([#Seq],Table1[Seq],0))
Table2[Re-Order Qty]
=INDEX(IF(Table1[Re-Order Qty]>Table1[On-hand Qty],Table1[Re-Order Qty],"N/A"), MATCH([#Seq],Table1[Seq],0))
Table2[On-hand Qty]
=INDEX(IF(Table1[Re-Order Qty]>Table1[On-hand Qty],Table1[On-hand Qty],"N/A"), MATCH([#Seq],Table1[Seq],0))
The main idea behind these formulas is:
Return a new array based on the conditional. This new array will return the desired column (Item, Re-order, ...) or it will return N/A if the conditional is FALSE. This requires the array formula entry since it is going row by row in the IF.
The MATCH part of the formula to get the row number is "standard". We are simply looking for the Seq number in Table1. This determines which row of the new array to return.