Pulling and modifying data points from multiple external workbooks

MontgoJG

New Member
Joined
Jun 5, 2019
Messages
5
Greetings,

I am creating a workbook to consolidate data from two other workbooks created by exporting reports from an accounting system. Here are examples from the two exported workbooks:

WORKBOOK A
ItemCodeInvValue
A0.00
A619.42
E3.00
G289.56
C4,459.33
C44.59
I153.40
J139.18
K56.88
H794.82
F650.37
B184.38
B368.76
D1027.71
D355.45
D543.19

<tbody>
</tbody>


WORKBOOK B
ItemCodeInvTrans
A-130.81
B-420.15
C-3,354.76
D-1087.42
E-12.50
F-627.66
B-512.21
G-280.47
D-621.80
H-774.72
C-524.67
I-124.14
J-130.99
A-455.56
K-54.45
Z-15.24

<tbody>
</tbody>


Here is the result I'm looking for:

WORKBOOK C
ItemCodeInvValueInvTrans
A619.42-586.37
E3.00-12.50
G289.56-280.47
C4,503.92-3879.43
I153.40-124.14
J139.18-130.99
K56.88-54.45
H794.82-774.72
F650.37-627.66
B553.13-932.36
D1,926.35-1709.22

<tbody>
</tbody>


My first issue is that I need to have Workbook C take the ItemCode values from Workbook A and populate only the unique values. The second issue is that I will need Workbook C to populate those unique values and the SUMIF formulas used to give the totals per ItemCode for InvValue and InvTrans without having to open Workbooks A and B.

I look forward to learning the magic!

Justin
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
hello

One way is a query in workbook C. Defined by

Code:
SELECT C.ItemCode, SUM(C.InvValue) AS [InvValue], SUM(C.InvTrans) AS [InvTrans]
FROM (SELECT ItemCode, InvValue, 0 AS [InvTrans]
FROM `C:\YourPath\A.xlsx`.[Sheet1$]
UNION
SELECT ItemCode, 0, InvTrans
FROM `C:\YourPath\B.xlsx`.[Sheet1$]) C
GROUP BY C.ItemCode

Please change the file path & worksheet names (assumed Sheet1) to suit.
If the source files change, just refresh it (like a pivot table).

Manual set up: ALT-D-D-N & follow wizard, Excel files, etc. If you don't see source data take the option and add 'system tables'. Just get any data you can & at the last step of the wizard take the option to edit in MS Query. Within MS Query via the SQL button replace what you see by the above text. OK to enter & then the 'open door' icon to exit MS Query & set up the query in a worksheet. If you get stuck please google for further info/examples.

This will work in Excel for the last 20 years or so. There will be slightly different implementation available in recent Excel versions to do the same thing. Also you can do it with VBA - either a query table or alternatively ADO.

Another obvious alternative approach (which is almost identical) - that might be simpler or more familiar - is a pivot table.

regards
 
Upvote 0
With PowerQuery (Get&Transform) and PivotTable

Sum of ValueAttribute
ItemCodeInvValueInvTrans
A
619.42​
-586.37​
B
553.14​
-932.36​
C
4503.92​
-3879.43​
D
1926.35​
-1709.22​
E
3​
-12.5​
F
650.37​
-627.66​
G
289.56​
-280.47​
H
794.82​
-774.72​
I
153.4​
-124.14​
J
139.18​
-130.99​
K
56.88​
-54.45​
Z
-15.24​

Code:
[SIZE=1]
//PowerQuery Append1
let
    Source = Table.Combine({Sheet1, #"Sheet1 (2)"}),
    Unpivot = Table.UnpivotOtherColumns(Source, {"ItemCode"}, "Attribute", "Value")
in
    Unpivot[/SIZE]
 
Last edited:
Upvote 0
Thank you for the quick response. I have entered the query and adjusted it for the file path and file names, but when I attempt to run the query it give me a error that says:

Compile error:

Expected: Case

It highlights the first 'C' after the initial SELECT. Any ideas on what I might be doing wrong?



hello

One way is a query in workbook C. Defined by

Code:
SELECT C.ItemCode, SUM(C.InvValue) AS [InvValue], SUM(C.InvTrans) AS [InvTrans]
FROM (SELECT ItemCode, InvValue, 0 AS [InvTrans]
FROM `C:\YourPath\A.xlsx`.[Sheet1$]
UNION
SELECT ItemCode, 0, InvTrans
FROM `C:\YourPath\B.xlsx`.[Sheet1$]) C
GROUP BY C.ItemCode

Please change the file path & worksheet names (assumed Sheet1) to suit.
If the source files change, just refresh it (like a pivot table).

Manual set up: ALT-D-D-N & follow wizard, Excel files, etc. If you don't see source data take the option and add 'system tables'. Just get any data you can & at the last step of the wizard take the option to edit in MS Query. Within MS Query via the SQL button replace what you see by the above text. OK to enter & then the 'open door' icon to exit MS Query & set up the query in a worksheet. If you get stuck please google for further info/examples.

This will work in Excel for the last 20 years or so. There will be slightly different implementation available in recent Excel versions to do the same thing. Also you can do it with VBA - either a query table or alternatively ADO.

Another obvious alternative approach (which is almost identical) - that might be simpler or more familiar - is a pivot table.

regards
 
Upvote 0
My apologies, I realized I wasn't entering the query in the correct place.

I am in the query window now, and when I attempt to run the query it gives me the following message:

SQL Query can't be represented graphically. Continue anyway?

When I click 'OK' it gives me another message:

Could not add the table '(SELECT'.




Thank you for the quick response. I have entered the query and adjusted it for the file path and file names, but when I attempt to run the query it give me a error that says:

Compile error:

Expected: Case

It highlights the first 'C' after the initial SELECT. Any ideas on what I might be doing wrong?
 
Upvote 0
Just to clarify, I'm looking for something like this:


SELECT C.ItemCode, SUM(C.InvValue) AS [InvValue], SUM(C.InvTrans) AS [InvTrans]
FROM (SELECT t1.`Item Code` AS [ItemCode], t1.`Inventory Value at Standard` AS [InvValue]
FROM `FilePath\FileName.xlsx`.[Sheet1$] t1
LEFT JOIN
SELECT t2.`Item Number`, t2.`Value` AS [InvTrans], t2.`Transaction Type` AS [TransType]
FROM `FilePath\FileName.xlsx`.[Sheet1$] t2
ON t1.ItemCode = t2.`Item Number`
WHERE t2.TransType = "WIP Issue") C
GROUP BY C.ItemCode


I can't get it to work in the query window, I'm assuming due to some syntax I don't know.
 
Upvote 0
That is a 'LEFT JOIN' that won't work in any database AFAIK.
the guts of the query basically say SELECT two fields FROM t1 LEFT JOIN SELECT three fields FROM t2
Normally syntax is SELECT some fields FROM table

Compare that with the UNION that was suggested.

The SQL shows you want a different result from the original question.

Best to clarify the workbook names, worksheet names, field names, etc. That is, what is posted in the thread matches what you test on: and anyone helping working on the same set up.

PS. I tested on the set up as originally posted & the SQL I posted worked for me.
 
Last edited:
Upvote 0
Sorry for the confusion, here are the details:

Workbook A:

Workbook name: Aged Inventory JPL 1904.xlsx
Worksheet name: Sheet1
Field names: Item Code, Inventory Value at Standard

Workbook B:

Workbook name: JEI Transaction Register for Costing JPL Rolling 12 Months 1904.xlsx
Worksheet name: Sheet1
Field names: Item Number, Value


The tables should be left joined on 'Item Code' = 'Item Number' and Workbook B needs to include the clause WHERE 'Transaction Type' = "WIP Issue" (don't need to see the Transaction Type in the output)

Please let me know if you need any other information.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,575
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top