Is it possible to insert a calculated column (table 1) based on another table (table 2)? Prefer to do it this way instead of joining table because the data on table 2 may keep on changing.
Calc column is derived by taking the f1 value on Table 2 based on matching value from col X on Table 1 to the nearest p1 value of Table 2. If it is possible to do a calculated column based on another table, how do I create an expression for it?
#p.ysl - In order to add column 'f1' to Table 1, Columns 'x' from Table 1 and 'p1' from Table 2 should be matched. As the format of these columns are not the same (one is real and the other is integer), we cannot match them. Though we do, 'f1' added to Table 1 will be blank as the values don't match.
You can add a calculated column to Table 1 with round values. example: 29.23 will be 29 in this column and then add column 'f1' from Table 2 by comparing calculated column 'round(x,0)' from Table 1 and column 'p1' from Table 2. But, the issue is calculated columns cannot be used for relating tables.
One solution is to freeze this calculated column in order to use it for matching columns. But, when we freeze the column, the entire table will be embedded and data cannot be refreshed.
However, you can accomplish this with an R-script.
Go to Register data function under Tools menu:
In the script section, add below script.
t3 <- cbind(t1, round(t1,0))
In Input Parameters section, define what 't1' is.
In Output parameters section, define what t3 is. In this case, the result will be stored as a table.
Now, RUN the script
It will prompt you to assign input and output parameters. Input - assign column 'x' from table 1.
Output parameter will be a new table.
Note: You can save this data function if you want to.
Table 't3' is created. Now, you can add 'f1' column from Table 2 to this table by matching 'column2' and 'p1' as shown in the screenshot below.
To ensure this runs dynamically, Table 1 and Table 2 can be embedded but t3 table should be linked to source so that when new data gets added to Table 1/ Table 2, t3 will be updated automatically.
Hope this helps!
Related
In one formula, I am trying to multiply and then sum up data in 2 different tables based off of criteria selected for both tables.
So, if the user picks data from column 1 in the first table but column 3 in the second table, I want to use the corresponding amounts. I tried using Sumproduct but couldn't get it to work.
I used =SUMPRODUCT(ExpenseBase * ExpenseMultiplier*(ModelTypeBase=Type)*(MultiplierTypes=Multiplier))
ExpenseBase is the data in table 1, ExpenseMultiplier is data in table 2, ModelTypeBase is the top labels in table 1 and MultiplierTypes is the top labels in table 1. If I choose X and A, I get the right answer, but if I choose B in the second table it goes to 0.
Base Tables
[1]: https://i.stack.imgur.com/S72yY.png
Use INDEX to return the correct column
Capital:
=SUMPRODUCT(INDEX($B$3:$D$10,0,MATCH($B$17,$B$2:$D$2,0)),INDEX($G$3:$I$10,0,MATCH($B$18,$G$2:$I$2,0)))
Then for Expense we change the lookup ranges:
=SUMPRODUCT(INDEX($B$12:$D$14,0,MATCH($B$17,$B$2:$D$2,0)),INDEX($G$12:$I$14,0,MATCH($B$18,$G$2:$I$2,0)))
I have a table that looks like this:
Type Value
Movie 5
Food 3
Gas 10
Food 2
.... ....
And There's a second table I want to fill in with "Value" based on their type in the first table, so that the corresponding rows look like this:
Rent Food Movie Gas Clothing ... ( appear in specific order bc they are subcategories)
5
3
10
2
The title row is already there, so I was thinking there might be some kind of lookup method to do this? How do I do that?
your second table apperas to hold one value per row but it doesn't have a label. it does correlate to the original row number, is this by design or coincidence?
if this is by design then you can use those 2 columns, hide them if you like, get a unique list of categories by copying you r abels to a new colum, removing duplicates in the data tab, then paste special transpose in c1 to create colum headers.
so column a and b remain unchanged
row 1 contains header starting at column c
your data starts at c2
this is the formula
=Iferror(vlookup(C$1,$A2:$B2,2,false),"")
drag it down and to the right
you can copy paste special values when done to remove the formulas
for something with only a hundred or thousand cells this will be one of the easier options but i would not do this on large tables, for those i would use power query or VBA
Assuming your 1st table is in Sheet1 and 2nd table is in sheet2.. you may try to fill in Sheet2!A2
=IF(Sheet1!$A2=A$1,Sheet1!$B2,"")
and drag it all the way.. Hope you get how it works.. and what you need.
First allow me to provide some background:
I have two tables, the first with one column that has a key value, which is just one letter of the alphabet and a second column with values that later I want to sum. The second table also has two columns. The first contains a list of the distinct values from the key column of the first table, and the second contains a binary value of 1 or 0. Examples below:
Table 1: Table 2:
A 50 A 1
A 50 B 0
B 100 C 0
C 125
The binary values in Table 2 are variable based on other information contained in my workbook. Now what I want to do is to sum all of the values in Table 1, where the Primary key is "turned on" in Table 2, aka the value in the second column is 1. I've tried multiple iterations of using SUMIF and VLOOKUP and LOOKUP as the criteria but can't get anything to work. Can anyone help out with a way, either using VBA or in the cell formula itself, to get this done?
Thanks in advance.
How's this? Place this next to the 1 or 0 in your Table2, =IF(F1>0,SUMIFS($B$1:$B$4,$A$1:$A$4,E1),""):
and if you drag that down, it'll return blanks for the "letter" that doesn't have duplicates.
Edit: Or, per #pnuts, this =SUMIF(A:A,"="&INDEX(E:E,MATCH(1,F:F,0)),B:B)
Excel - trying to identify top 3 sales numbers in column D (D5:D:41), and return information from corresponding column A (A5:A41)
You can get the top 3 with
=INDEX($A$5:$A$41,MATCH(LARGE($D$5:$D$41,ROW(A1)),$D$5:$D$41,0))
Copy down two rows.
You could use a pivot table to very easily get his information.
Select insert a pivot table
Select your data
In the pivot table window place the 'Name' field into the 'Row Labels' box and the 'Sales' field into the 'Values' box.
This should give you a pivot table with a list of people and the sum of their sales, making it very easy to see who comes out top.
I have two tables in two different sheets. In Table 1 and table 2 column 1 is for id's. but in Table 2 I have more id's than table 1.
What I want is: if a cell in table 2 column 2 is filled to check the id and if its in table 2 to mark "yes" in column 2 in Table 1.
This is the code I have been using but it stops when the ids don't match:
=IF(AND(Table 2[column 2]>0,VLOOKUP([column 1],Table 2[column 1],1,FALSE)=sheet 2!A5),"yes","")
You could put something like this in table 1 column 2. Assuming table 1 is in columns A,B and Table 2 is in columns D,E. That is column D is the id in table 2 and column E is the value in table 2.
This will return an error if there is an id in table 1 that isn't in table 2. To deal with this you could wrap it with iferror.
=IF(INDEX($E:$E,MATCH(A1,$D:$D,0))>0,"yes","")
Gordon
You might try:
=IFERROR(IF(VLOOKUP(Table1[[#This Row],[column 1]],Table2[#All],2,0)<>"","yes",""),"")
at the top of column 2 of Table1, adding spaces in the table names if you have been able to.