Forum Discussion
Inventory opening closing
- Anonymous11 months ago
Hi rajasekaro ,
Let me give you the ready-to-use Power Query (M) solution that will works for you.
- Sort the data by Docdate.
- Create Received and Issued columns.
- Calculate Running Closing balance.
- Calculate Opening (previous closing, first row = 0).
- Produce two outputs.
- Detail Ledger (row-wise)
- Summary Statement (Opening=0, total Received, total Issued, Closing).
use the bellow M code.
let
// Replace with your source table name
Source = YourTable,
// 1. Sort by Docdate
Sorted = Table.Sort(Source, {{"Docdate", Order.Ascending}}),
// 2. Add Received & Issued columns
AddReceived = Table.AddColumn(Sorted, "Received", each if [TYPE] = "RCPT" then [QTY] else 0, type number),
AddIssued = Table.AddColumn(AddReceived, "Issued", each if [TYPE] = "ISSU" then [QTY] else 0, type number),
// 3. Add Index column
AddIndex = Table.AddIndexColumn(AddIssued, "Index", 1, 1, Int64.Type),
// 4. Add Closing as running balance
AddClosing = Table.AddColumn(AddIndex, "Closing", each
List.Sum(List.FirstN(AddIndex[Received],[Index]))
- List.Sum(List.FirstN(AddIndex[Issued],[Index]))
, type number),
// 5. Add Opening = Previous row Closing (first row = 0)
AddOpening = Table.AddColumn(AddClosing, "Opening", each
if [Index] = 1 then 0
else AddClosing[Closing]{[Index]-2}
, type number),
// 6. Reorder columns
DetailLedger = Table.ReorderColumns(AddOpening, {"Item","Docdate","Opening","Received","Issued","Closing"}),
// 7. Create Summary Statement
OpeningVal = 0,
ReceivedVal = List.Sum(DetailLedger[Received]),
IssuedVal = List.Sum(DetailLedger[Issued]),
ClosingVal = OpeningVal + ReceivedVal - IssuedVal,
Statement = #table({"Item","Docdate","Opening","Received","Issued","Closing"}, {{"Statement","",OpeningVal,ReceivedVal,IssuedVal,ClosingVal}})
in
[DetailLedger = DetailLedger, Statement = Statement]
If you still face any issues, let us know happt to help.
Thanks,
Akhil
Hi rajasekaro
Create the following measures:
Sum of qty =
SUM ( inventory[QTY] )
Opening =
CALCULATE (
[Received] - [Issued],
FILTER (
ALL ( inventory[Docdate] ),
inventory[Docdate] < MIN ( inventory[Docdate] )
)
)
Received =
CALCULATE ( [Sum of qty], KEEPFILTERS ( inventory[TYPE] = "RCPT" ) )
Issued =
CALCULATE ( [Sum of qty], KEEPFILTERS ( inventory[TYPE] = "ISSU" ) )
Closing =
CALCULATE (
[Received] - [Issued],
FILTER (
ALL ( inventory[Docdate] ),
inventory[Docdate] <= MAX ( inventory[Docdate] )
)
)
or
Closing =
[Opening] + [Received] - [Issued]
- rajasekaro11 months agoHelper III
i have inventory data need to calculate opeing closing to create detail ledger
Table: STOCKVALUEItem Docdate QTY TYPE docid BP Monitor 19-03-2024 150 RCPT do1 BP Monitor 17-04-2024 10 ISSU do2 BP Monitor 01-07-2024 150 RCPT do3 BP Monitor 03-07-2024 10 ISSU do4 BP Monitor 04-07-2024 300 RCPT do5 BP Monitor 02-12-2024 100 ISSU do6 BP Monitor 27-12-2024 250 RCPT do7 BP Monitor 21-01-2025 250 RCPT do8 BP Monitor 19-02-2025 150 RCPT do9 BP Monitor 13-03-2025 100 RCPT do10 BP Monitor 15-04-2025 250 RCPT do11 BP Monitor 30-04-2025 200 ISSU do12 BP Monitor 05-07-2025 300 ISSU do13 BP Monitor 21-08-2025 200 RCPT do14
EXPECTED OUTPUT
1.Detail Ledger2.Statement
- Shahid1252311 months agoCommunity Champion
Do it in Power Query (easiest):
1.Sort by Docdate.
2.Add columns:
- Received = if TYPE="RCPT" then QTY else 0
- Issued = if TYPE="ISSU" then QTY else 0
3.Add Closing = running sum of (Received ā Issued).
4.Add Opening = Previous row Closing (shifted down, first = 0).
Result ā Detail Ledger.
For Statement:
- Opening = 0
- Received = SUM(Received) = 1800
- Issued = SUM(Issued) = 620
- Closing = 1180 ā
- rajasekaro11 months agoHelper III
NOT working
- kushanNa11 months agoSuper User
Duplicate ? https://community.fabric.microsoft.com/t5/Desktop/Inventory-opening-closing/m-p/4814555#M1431892
- mh258711 months agoSuper User
You already posted same thread,
https://community.fabric.microsoft.com/t5/Desktop/Inventory-opening-closing/m-p/4814555#M1431892