Excel 2016多表数据合并求助:按ID匹配计算生成结果表
Hey there! Let's tackle this Excel 2016 problem step by step. Based on your requirements, here are a couple of reliable methods to get your result table updated automatically whenever your input or supplementary tables change:
Power Query is ideal here because it simplifies combining tables and lets you refresh the result with one click whenever your source data changes—perfect for monthly updates.
Load tables into Power Query
- Select your input table, go to the
Datatab >From Table/Range(ensure your table has clear headers) - Repeat this step for your supplementary table, so both are loaded into the Power Query editor
- Select your input table, go to the
Combine and aggregate data
- In the Power Query editor, go to the
Hometab >Append Queries>Append Queries as New - Select both your input and supplementary tables, then click
OKto merge all rows - Select the
IDcolumn, navigate to theTransformtab >Group By- In the Group By window:
- Set
Group bytoID - Add two aggregation rules:
- For
CASH: ChooseSumas the operation, then select your CASH column - For
HOURS: ChooseSumas the operation, then select your HOURS column
- For
- Set
- In the Group By window:
- Click
OK, and you’ll have a table grouped by ID with summed values for matching entries
- In the Power Query editor, go to the
Load the result back to Excel
- Go to the
Hometab >Close & Load To> ChooseTableand pick where you want your result table to appear - Whenever your input or supplementary tables update, just right-click the result table >
Refreshto sync the changes
- Go to the
If you’d rather use direct formulas in your result table, here’s how to cover all three scenarios:
First, generate a unique list of all IDs from both tables. Enter this formula in the first cell of your result table’s ID column (e.g., cell A2):
=IFERROR(INDEX(InputTable[ID], ROWS($A$2:A2)), IFERROR(INDEX(SupplementaryTable[ID], ROWS($A$2:A2)-ROWS(InputTable[ID])), ""))
Drag this formula down until you see blank cells to cover all IDs from both tables.
For the CASH column (e.g., cell B2):
=SUMIF(InputTable[ID], $A2, InputTable[CASH]) + SUMIF(SupplementaryTable[ID], $A2, SupplementaryTable[CASH])
For the HOURS column (e.g., cell C2):
=SUMIF(InputTable[ID], $A2, InputTable[HOURS]) + SUMIF(SupplementaryTable[ID], $A2, SupplementaryTable[HOURS])
Drag these formulas down to all rows of your result table. This will automatically sum values for IDs present in both tables, pull the single value for IDs only in one table, and return 0 for any unmatched entries (you can adjust this with an IF statement if you prefer blanks instead of 0).
Quick Notes:
- Replace
InputTableandSupplementaryTablewith the actual named ranges of your tables (go to theFormulastab >Define Nameto name your tables for easier reference) - For the formula method, if new IDs are added to your input or supplementary tables, you’ll need to drag the ID formula down to include them. Power Query eliminates this extra step with a simple refresh.
If you run into any snags—like formula errors or issues with Power Query refresh—feel free to share more details about your table structure, and I’ll help you troubleshoot further!
内容的提问来源于stack exchange,提问作者Leemosh

