Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I want to use sheet 1 to filter the query on Sheet 2

Posted on 2011-02-18
15
Medium Priority
?
279 Views
Last Modified: 2012-05-11
I have an Excel spreadsheet, sheet 1 finds all data of merchandise that has been returned.  On sheet 2 I want to create a table that finds the location of where to put the returned items.  I can create a query that combines 2 tables on ItemKey.  However, I am getting all the data in Sheet2 instead of just the returned items.  I created an external datasource using Data -> From Other Sources -> Microsoft Query, pointing to the Big Database and getting only the following : Table1.ItemKey, Table2.ItemKey, quantity and Location. where Table1.ItemKey = Table2.ItemKey.  How do I limit the output to just the items in Sheet 1?
0
Comment
Question by:chaverly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 2
15 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928048
Specify that it be an INNER JOIN
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928053
If that doesn't make sense, then post the query, please.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34928101
I think what he wants to do is select the data in the two table based on the data set in the excel sheet already.

Something like (Suedo sql code)

SELECT * from Table1,Table2
WHERE Table1.id = Table2.ID
AND
Table1.ID IN ( SELECT ID FROM Excel.workbook.NamedRangeOnSheet1 )
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928212
Right, but specifying inner join will do the same thing since it will only pull values that exist in both tables.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34928315
No, if sheet one only has 10 rows with unique ID's he ONLY wants those 10 records from the db not all 50,000
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928431
Please do at least a simple Google search before arguing with another expert.
http://www.w3schools.com/sql/sql_join.asp
INNER JOIN will only pull records that exist in both tables.

It does matter what kind of query you are running though. If it's an SQL query than joins apply, otherwise you might need something else.

SELECT Table1.ItemKey, Table2.ItemKey, Table2.quantity, Table2.Location
FROM Table1 INNER JOIN Table2 ON Table1.ItemKey = Table2.ItemKey
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928439
Some programs use JOIN in place of INNER JOIN
0
 

Author Comment

by:chaverly
ID: 34928508
Neilsr is correct.  I want to look at an item in sheet 1 and find the corresponding 4 fields in Sheet 2 and record them on Sheet 3.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34928515
Nobody is argueing. IF you read what both the questioner AND I said you will see what your mistake is.

We KNOW how a join works. That is on the two tables in the database. HE ALSO wants to filter on the data in sheet one at the same time to reduce the subset of data returned.  

YOUR query takes into account ONLY the two tables in the external database.

So please, next time before you you critisise ME or anybody else, READ THE QUESTION AND THE COMMENTS.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928846
Oh, I see. I was assuming that Table1 was on Sheet1. If you do the join with sheet1 as one of the tables, it would work.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34928860
So just join all three tables.
Sorry about all that.
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 1000 total points
ID: 34928863
OK Here goes....

I have made a few assumptions but bear with me.

In your spreadsheet assume your data in sheet1 has an Index column in column A that is your IndexKey

once you have your data in sheet 1, define a named range on column A

Now in your database you need to ad a LINKED TABLE that is infact sheet1 of your excel sheet.  So your database now has 3 tables. Table1, Table2 and your linked table called DATA1

Now you can do a Get external dataFrom another source in sheet 2 that has the following SQL Query as its source.

SELECT  Table1.IndexKey, Table1.Field1, Table1.Field2, Table1.Field3, Table2.IndexKey, Table2.F1, Table2.F2
FROM `C:\Documents and Settings\neilrsr\My Documents\Database1.accdb`.Data1 Data1, `C:\Documents and Settings\neilrsr\My Documents\Database1.accdb`.Table1 Table1, `C:\Documents and Settings\neilrsr\My Documents\Database1.accdb`.Table2 Table2
WHERE Table1.IndexKey = Table2.IndexKey AND  Table2.IndexKey = DATA1.F1

That should get your query set to return ONLY records from the database where the IndexKey is in column A of Sheet1.

0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34928879
You may be able to do it without the linked table by referencing sheet1 directly I dont know. Maybe TommySzalap… can advise?
0
 

Author Closing Comment

by:chaverly
ID: 34928957
Thank you both so much.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34929004
There are ways to pull parameters from a query directly from cells in Excel without linked tables, but use what works for you. I don't want any points on this one anyway because I kind of made a fool of myself.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question