Equivalent to Joining tables (SQL) in Excel?

Click For Summary
To compute expressions like A/B using data from different sheets in Excel, users can reference cells across sheets directly, similar to SQL joins. Excel allows for formulas that reference other sheets, enabling calculations like ratios. However, exporting data to SQL Server is often recommended for better data management and complex queries. PivotTables can consolidate data from multiple sheets, but users may face challenges when trying to filter or calculate ratios across sheets with non-matching entries. In cases where Microsoft Query fails to connect, users can directly execute SQL queries within Excel to retrieve and manipulate data. For one-to-one relationships, functions like VLOOKUP can be utilized, while aggregating data may require careful handling of joins in SQL to ensure accurate results. Overall, while Excel can perform these calculations, leveraging SQL Server may provide a more robust solution for complex data analysis.
  • #31
WWGD said:
Ah, never mind. In case anyone is interested for the SQL format:
We want to compute the ratio SUM(f_1)/COUNT(f_2) , f1 in table 1 (T1), f2 in table 2 (T2);
f_12 a common field , over values in f_12 common to T1, T2.
This runs: EDIT

SELECT A/B FROM
( SELECT SUM(f_1) AS A
FROM T1 JOIN T2 on T1.f_12=T2.f_12 GROUP BY f_12) AS Table1
JOIN
(SELECT COUNT(f_2) AS B FROM T1 JOIN T2 ON T1.f_12=T2.f_12
GROUP BY f_12 ) AS Table2
ON Table1.f_12 =Table2.f_12
GROUP BY f_12

Sorry to all for dragging this along so far.

Have you found a solution yet?
I do sql in Excel now and then (ODBC) using some time sheets in the same file as tables, but also sometime sheets in differents files.
I know you can do simple join operations. See this link with some .xlsx examples and a ReadMe.txt file:
https://www.dropbox.com/sh/awoes8lgpj76igb/AABZOAEq7pF36kIXKykn3PKga?dl=0

In file T_Queries, I put A and B in different columns and did A/B the old school Excel way in a formula but you can play around with more complex join queries and see how Excel handles it.. (Ribbon > Data > Connections > DoubleClick on Connection > Definition).
Those two queries use tables/sheets being in the same file (T_1_and_2.xlsx).

Another query, just for fun, uses tables/sheets being in 2 different files (T_1.xlsx and T_2.xlsx).
It's cool that one can use a virtual database of excel files being all over the place and query it using our dear friends SQL and ODBC!

Let us know it this helps a little in what you were trying to achieve.
 
Last edited:
  • Like
Likes WWGD
Computer science news on Phys.org
  • #32
Tokinabo said:
Have you found a solution yet?
I do sql in Excel now and then (ODBC) using some time sheets in the same file as tables, but also sometime sheets in differents files.
I know you can do simple join operations. See this link with some .xlsx examples and a ReadMe.txt file:
https://www.dropbox.com/sh/awoes8lgpj76igb/AABZOAEq7pF36kIXKykn3PKga?dl=0

In file T_Queries, I put A and B in different columns and did A/B the old school Excel way in a formula but you can play around with more complex join queries and see how Excel handles it.. (Ribbon > Data > Connections > DoubleClick on Connection > Definition)

Those two queries use tables/sheets being in the same file (T_1_and_2.xlsx).
Another query, just for fun, uses tables/sheets being in 2 different files (T_1.xlsx and T_2.xlsx).

Let us know it this helps a little in what you were trying to achieve.
Thanks. I was able to do it in SQL , but I had trouble using Microsoft query within Excel; somehow the connection was not working well ( despite the fact that the Wizard had no trouble sending data back-and-forth). Thanks for your refs., will check them out.
 

Similar threads

Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
6
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 51 ·
2
Replies
51
Views
5K
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K