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.
Related
I have a data set that looks something like this-
Item
Value
A
1
A
2
A
3
B
1
B
2
B
3
C
1
C
2
And I want to convert it to this -
Item
Value
A
1,2,3
B
1,2,3
C
1,2
Using your provided example data, and assuming a data setup like this:
In cell D2 and copied down is this formula to get unique items: =INDEX($A$2:$A$9,MATCH(0,COUNTIF(D$1:D1,$A$2:$A$9),0))
In cell E2 and copied down is this formula to get the joined values: =TEXTJOIN(",",TRUE,REPT($B$2:$B$9,$A$2:$A$9=D2))
Adjust the ranges to suit your actual data.
I'm trying to count the following in excel:
I have a number of unique values for X (say 4), each appearing twice (in random order) in the data set. I want to count the number of each combination (regardless of order) of values on a second column Y for each value of X.
Example (here in order):
X Y
1 A
1 D
2 A
2 C
3 B
3 C
4 A
4 D
As output, I need:
n A,D 2
n A,C 1
n B,C 1
n B,D 0
(Let's assume all other combinations don't exist.)
Is this possible without rearranging the data? I don't mind putting in 4 formulas (for each possible combination).
My starting point was akin to this: excel count unique combinations of columns, but I can't quite figure it out and also I know what feels like next to nothing about excel or coding...
To get the count of pairs if the data is not in order, first one needs to get the pairs by X. Create a unique list of X and use this formula:
=CHAR(AGGREGATE(15,6,CODE($B$2:$B$9)/($A$2:$A$9=D2),1))&","&CHAR(AGGREGATE(15,6,CODE($B$2:$B$9)/($A$2:$A$9=D2),2))
Note this only works if the Y is one character like your data.
Then create a unique list of that output and use a standard COUNTIF:
=COUNTIF(E:E,G2)
Or you can use a pivot table on the first helper columns to get the same without the need of getting the unique pairings.
If you use a helper column, you can combine the data into something you can count. Use the formula =IF(A2<>A1,B2,C1&","&B2) in column C. So your data then becomes:
X Y
1 A A
1 D A,D
2 A A
2 C A,C
3 B B
3 C B,C
4 A A
4 D A,D
Then it's a matter of counting up the combinations. Here's a snapshot of my example:
You can use the MMULT function for this purpose, like this (You can insert line breaks with Alt+Enter but you do not have to, it also works if you write it on the same line):
=SUMPRODUCT(
--($B$2:$B$19= LEFT($D2,FIND(",",$D2)-1) ),
MMULT(
--($A$2:$A$19=TRANSPOSE($A$2:$A$19)),
--($B$2:$B$19= MID($D2,FIND(",",$D2)+1,LEN($D2)) )))
You have to enter this as an array formula (After typing, press Ctrl+Shift+Enter, instead of just Enter; you will see the formula inside braces, like this: {=...}).
Here is a screenshot to show what the ranges in the formula mean:
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
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.
I'm trying to rearrange a pivot table that organizes all values (not sum or other statistic) from an original table. Seems simple but I can't find a way to make it values rather than sums.
My original data looks like:
Rank Name
1 A
1 B
2 C
2 D
3 E
3 F
and with the pivot table I get something like:
Rank Name
1 A
B
2 C
D
3 E
F
and I would like to rearrange it like so:
1 2 3
A C E
B D F
There's a way to achieve that using array functions instead of pivot tables.
Suppose your original data is located in A1:B7.
To get the headers row (1, 2, 3):
A10: =MIN(A2:A7)
B10: =SMALL($A$2:$A$7,COUNTIF($A$2:$A$7,"<="&A10)+1)
Then copy B10 as far right as you need to get all other values
To get the values for each rank, set an array formula (Ctrl+Shift+Enter) on the range A11:A16 (or lower to fit more items) with this formula:
=IFERROR(INDEX($B$2:$B$7,SMALL(IF($A$2:$A$7=A$10,ROW($A$2:$A$7)-ROW($A$2)+1),ROW()-ROW(A$10))),"")
Then copy this range (A11:A16) as far right as you need...