Two Tables Excel values - excel

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.

Related

Multiply and Sum Data from 2 tables based off of Multiple Criteria

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)))

How to duplicate and sync tables based on ID column in Excel?

I'd like to duplicate a table in Excel onto a different worksheet, add columns to the new table, and keep the rows synced.
(p.s I'm not sure how to add images of the Excel sheet in here?)
For example, I have a table (Table1):
ID Data
A 1
B 2
C 3
D 4
I'd like to duplicate it in another sheet (Table2) and add a column that's only in the new table:
ID Data Data2
A 1 a
B 2 b
C 3 c
D 4 d
And I'd keep the rows synced, so that if I add, delete or amend a row in the original table (Table1), the new table (Table2) remains consistent including the added column that only exists in the new table.
For example, if I delete the row with ID "B" in the original table, I'd like this to happen in the new table:
ID Data Data2
A 1 a
C 3 c
D 4 d
I've been able to duplicate the table via a connection or query, but the added column in the new table doesn't stay in sync. For example, at the moment if I delete the row with ID "B" in the original table, this happens in the new table:
ID Data Data2
A 1 a
C 3 b
D 4 c
The columns that are in the original table update correctly, while the new column seems to be ignored.
I need to use Excel and if possible without VBA, but if VBA is the only way this will work then I'll need to use it.
I'm pretty desperate so any tips in the right direction would be gratefully received!!

Spotfire: calculated column based on column in another table

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!

excel pivot table - count appearance of certan value in column

let's say i have folowing data for my excel pivot table:
country_id user_id answer
---------- ------- ------
1 1 Y
1 2 Y
2 3 N
2 4 Y
3 5 N
i would like to count how many "Y" i have per country.
If i put "answer" in Values as "Count of answer" i get 1 for each row. How can i count only "Y" answers?
so the result will be:
country_id answerY
----------- -------
1 2
2 1
3 0
br
Y
I have a solution similar to #pkg. Add one more column in your data and call it "answerY" with the formula:
=IF(C4="Y",1,0)
or, if your data is in a table:
=IF([#answer]="Y",1,0)
Now, set up your pivot table as follows:
Row lables: country
Values: answerY (sum)
Ordinarily I'd say to add a calculated field in a pivot table, but calculated fields work off of the aggregate values, and I can't think of a way to do this with a straight pivot table.
If you have the ability to use PowerPivot, you could create a custom column or a Dax expression that would handle this.
I'm not sure you can do that in a pivot table, but if you would like to do it outside of a pivot table you could make a couple of columns with these formulas:
Column D:
=IF(C2="Y",1,0)*A2
Column E:
=COUNTIF(D$2:D$6,B2)
This assumes that all user IDs are unique and sequential, and D$6 needs to be replaced with whatever is the last value in the column. Column E will have the values you described as answerY.

Grouping rows in table in Excel

I have the following table:
First Name Second Name Phone
A B 1
A B 2
C D 3
C D 4
I would like to get the required table (Every values in columns A and B that repeats will appear only in the first line of occurrence):
First Name Second Name Phone
A B 1
2
C D 3
4
You can accomplish this by using Pivot Tables.
Out of my head, you have to structure it like this:
Rows
First Name
Second Name
Phone
And it will show it the way you want it. You can change the show/hide for (sub)totals to change the result a bit.
If you want the First name and Second name on the same row, you will have to edit the Pivot Table to use Classic display.

Resources