Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi all
Very new to coding in power query and just started using Power Pivot.. but getting there slowly, building myself up to get into Power Bi
basically i have 3 tables which i need to transform
1/ STOCK onhand - Type = Stock, Code , QTY Transaction date = Today - per item could have various Qty in same day
2/ STOCK IN WARD -Type = Work order, Code , QTY Transaction date = various - per item could have various Qty's in same day
3/ STOCK OUT WARD Type = Sales order , Code, QTY , Transaction date = various - per item could have various Qty's in same day
Examples of my Tables (simplified)
| TYPE | CODE | QTY | DATE |
| STOCK | A1 | 6 | 31/07/2025 |
| STOCK | A1 | 4 | 31/07/2025 |
| STOCK | C1 | 1 | 31/07/2025 |
| TYPE | CODE | QTY | DATE |
| WORK ORDER | B1 | 20 | 31/07/2025 |
| WORK ORDER | A1 | 20 | 02/08/2025 |
| WORK ORDER | A1 | 10 | 03/08/2025 |
| WORK ORDER | B1 | 2 | 28/08/2025 |
| WORK ORDER | A1 | 10 | 05/09/2025 |
| WORK ORDER | C1 | 10 | 05/09/2025 |
| TYPE | CODE | QTY | DATE |
| SALES ORDER | A1 | 20 | 01/07/2025 |
| SALES ORDER | A1 | 10 | 01/07/2025 |
| SALES ORDER | A1 | 10 | 01/08/2025 |
| SALES ORDER | B1 | 20 | 02/08/2025 |
| SALES ORDER | C1 | 6 | 03/09/2025 |
The calculation = Stock qty per code + Work order per code - Sale order per code ( did do a power pivot measure with this calculation, but the qty's are not accumulated from 1 period (date) to the next )
so for any give date (time frame) I can create a power pivot table to pull through as below
| July | August | Sept | ||||||||
| CODE | NET STOCK | WORK ORDER | SALES ORDER | NET STOCK | WORK ORDER | SALES ORDER | NET STOCK | WORK ORDER | SALES ORDER | NET STOCK |
| A1 | 10 | 0 | 30 | -20 | 30 | 10 | -10 | 10 | 0 | 0 |
| B1 | 0 | 20 | 20 | 0 | 2 | 0 | 2 | 0 | 0 | 2 |
| C1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 10 | 6 | -5 |
| D1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
as an add on for STOCK table I have a created date = today. however Sales Order or Work Order Dates could be in the Past.. Is there a away If all these tables are joined that it will reflect the earliest date in the full data set.
Any help in how I pull these 3 tables together to get the desired output would be greatly appreciated , and which i will ofc added to my Power Query/ Power Pivot (Bi) knowledge
Solved! Go to Solution.
Hey @ianburns143,
Looking at your issue, I can see the problem. Your measures are summing ALL transactions across the entire dataset instead of respecting the pivot table's row context (CODE and DATE). The ALL(Transactions) function is removing all filters, which is why you're getting totals across everything.
Here's the alternate approach:
Replace your current measures with these corrected versions:
1. Net Inventory (Fixed):
Net Inventory = SUM(Transactions[FINAL QTY])
2. Accumulated Net Inventory (Fixed):
Accumulated Net Inventory =
CALCULATE(
SUM(Transactions[FINAL QTY]),
FILTER(
ALL(Dates[Date]),
Dates[Date] <= MAX(Dates[Date])
)
)
3. Individual Transaction Types (Fixed):
STOCK =
CALCULATE(
SUM(Transactions[FINAL QTY]),
Transactions[TYPE] = "STOCK"
)
WORK ORDER =
CALCULATE(
SUM(Transactions[FINAL QTY]),
Transactions[TYPE] = "WORK ORDER"
)
SALES ORDER =
CALCULATE(
SUM(Transactions[FINAL QTY]),
Transactions[TYPE] = "SALES ORDER"
)
Try these corrected measures and your pivot table should now show the proper running totals by item code and date as desired.
Fixed? ✓ Mark it • Share it • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
Hey @ianburns143,
You need to create a running total inventory calculation that combines three transaction types and accumulates values over time. The formula is: Stock On Hand + Work Orders - Sales Orders = Net Inventory.
Combine All Transaction Tables:
Source Tables Structure:
- TYPE | CODE | QTY | DATE
- Add calculated column: [Multiplier] = if [TYPE] = "SALES ORDER" then -1 else 1
- Final QTY = [QTY] * [Multiplier]
Establish Proper Date Relationships:
Base Inventory Measure:
Net Inventory =
SUMX(
ALL(Transactions),
Transactions[QTY] * Transactions[Multiplier]
)
Accumulated Inventory Measure:
Accumulated Net Inventory =
CALCULATE(
[Net Inventory],
FILTER(
ALL(Dates[Date]),
Dates[Date] <= MAX(Dates[Date])
)
)
Separate Calculations by Type:
Key Considerations:
Required Relationships:
Final Pivot Table Format:
CODE | DATE | STOCK | WORK ORDER | SALES ORDER | NET STOCK | ACCUMULATED NET
A1 | 31/07| 10 | 0 | 0 | 10 | 10
A1 | 01/08| 0 | 0 | 100 | -100 | -90
A1 | 02/08| 0 | 200 | 0 | 200 | 110
Data Consolidation Process:
Quality Assurance Steps:
Efficiency Considerations:
This solution will provide you with a robust inventory tracking system that accurately reflects accumulated net inventory positions over time, handling all your transaction types appropriately while maintaining data integrity and calculation accuracy.
Fixed? ✓ Mark it • Share it • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
Thank you so much for taking some time to show me this. I have followed your steps but I am not seeing the desired output. looks like it is summing all the Qty's across the dataset ,
Power Pivot Table below , with settings and what the desired output should look like
Here are the Steps followed
Source Tables
1/ I have alligned all the Fields across all 3 tables to have matching attributes
2/ I have created the date table (date only) running 1st day of my dataset to the last date
3/ In all 3 tables I have grouped all the Qty's having the same dates
Transaction Table
1/ Append all 3 tables together - output below
2/ Created the Calculated Multiplier and Final Qty columns as you requested
transaction table output
Power Pivot
1/Date table and transaction table loaded into Data Model and relationship established between dates
2/ I have created the following measures in the Transaction table
a) Net Inventory:=SUMX(ALL(Transactions),Transactions[QTY] * Transactions[Multiplier])
b) Accumulated Net Inventory:=CALCULATE([Net Inventory],FILTER(ALL(Dates[Date]),Dates[Date] <= MAX(Dates[Date])))
c) STOCK:=SUMX(FILTER(Transactions,Transactions[TYPE] = "STOCK" ),Transactions[FINAL QTY])
d)WORK ORDER:=SUMX(FILTER(Transactions,Transactions[TYPE] = "WORK ORDER" ),Transactions[FINAL QTY])
e)SALES ORDER:=SUMX(FILTER(Transactions,Transactions[TYPE] = "SALES ORDER" ),Transactions[FINAL QTY])
I am probally missing something simple, but if you could advise it would be greatly appreciated
Hey @ianburns143,
Looking at your issue, I can see the problem. Your measures are summing ALL transactions across the entire dataset instead of respecting the pivot table's row context (CODE and DATE). The ALL(Transactions) function is removing all filters, which is why you're getting totals across everything.
Here's the alternate approach:
Replace your current measures with these corrected versions:
1. Net Inventory (Fixed):
Net Inventory = SUM(Transactions[FINAL QTY])
2. Accumulated Net Inventory (Fixed):
Accumulated Net Inventory =
CALCULATE(
SUM(Transactions[FINAL QTY]),
FILTER(
ALL(Dates[Date]),
Dates[Date] <= MAX(Dates[Date])
)
)
3. Individual Transaction Types (Fixed):
STOCK =
CALCULATE(
SUM(Transactions[FINAL QTY]),
Transactions[TYPE] = "STOCK"
)
WORK ORDER =
CALCULATE(
SUM(Transactions[FINAL QTY]),
Transactions[TYPE] = "WORK ORDER"
)
SALES ORDER =
CALCULATE(
SUM(Transactions[FINAL QTY]),
Transactions[TYPE] = "SALES ORDER"
)
Try these corrected measures and your pivot table should now show the proper running totals by item code and date as desired.
Fixed? ✓ Mark it • Share it • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
Hi jainesh, this is perfect thank you so much for the solution, but more importantly thank you for giving me an insight into the actual coding and why it wasn't working.... very insightful!
Hey @ianburns143,
Thank you for the kind recognition - always happy to contribute!
Fixed? ✓ Mark it as solution • Give Kuddos • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
Sorry about the formating on the tables , didn't pull through as I expected , On the output should look like this
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |