track where the balance is coming from

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
547
Office Version
  1. 365
Platform
  1. Windows
hi all i have the below table
AM Balance Order Jul.08.24 (Part 3).xlsx
ABCDEFGHIJKLMNO
1ITEM #AM SNACKSORIGINAL BALANCE DATEORIGINAL BALANCEORDER DATE QTY ORDEREDBALANCERECEIVED DATEINVOICE #QTY RECEIVEDBALANCERECEIVED DATEINVOICE #QTY RECEIVEDBALANCE
200001apples9/6/2023811/2/2023758311/19/20239999107311/30/20231235023
300002oranges9/6/2023-3411/2/202350046611/19/202388884006611/30/2023456606
Sheet1
Cell Formulas
RangeFormula
G2:G3G2=D2+F2
K2:K3,O2:O3K2=G2-J2


i would like an excel formula on another sheet for each item to track the balance by date
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Your question is not clear, which is probably why you have had no replies.

What does "another sheet" look like, and for the data you have posted, what results do you expect to see?
 
Upvote 0
Your question is not clear, which is probably why you have had no replies.

What does "another sheet" look like, and for the data you have posted, what results do you expect to see?
Ok so for example on another sheet I would look up item number and return by date the sum of all balances
 
Upvote 0
... return by date the sum of all balances ...
Bear in mind we know nothing about your workbook other than what you post here.

Based on this description, I can't even guess what you are trying to do.

Can you please show us what "another sheet" looks like, preferably for more Sheet1 data than you have already posted.
 
Upvote 0
Bear in mind we know nothing about your workbook other than what you post here.

Based on this description, I can't even guess what you are trying to do.

Can you please show us what "another sheet" looks like, preferably for more Sheet1 data than you have already posted.
hi let me revise my question how can i unpivot this to look like a reg table vs same column names repeating over and over
 
Upvote 0
Are you looking for the output to look something like this ?

20241112 PQ Power Query Unpivot messy BORUCH.xlsm
ABCDEFG
1ITEM #AM SNACKSDateInvoiceNoTypeQtyBalance
21apples6/09/2023ORIGINAL BALANCE8
31apples2/11/2023ORDERED7583
41apples19/11/20239999RECEIVED-1073
51apples19/11/2023123RECEIVED-5023
62oranges6/09/2023123ORIGINAL BALANCE-34
72oranges2/11/2023123ORDERED500466
82oranges19/11/20238888RECEIVED-40066
92oranges19/11/2023456RECEIVED-606
Unpivot


I did this using mostly just the UI in Power Query (which I see you have used in the past).
The resulting code is below, I am sure that someone using M can do it in much less code.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ITEM #", "AM SNACKS"}, "Attribute", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 1, 1, Int64.Type),
    AddedCondColDate = Table.AddColumn(#"Added Index", "Date", each if Text.EndsWith([Attribute], "DATE") then [Value] else null),
    AddedCondColInvNo = Table.AddColumn(AddedCondColDate, "InvoiceNo", each if Text.StartsWith([Attribute], "INVOICE") then [Value] else null),
    AddedCondColBalance = Table.AddColumn(AddedCondColInvNo, "Balance", each if Text.Contains([Attribute], "BALANCE") and not Text.Contains([Attribute], "DATE") then [Value] else null),
    AddedCondColType = Table.AddColumn(AddedCondColBalance, "Type", each if Text.Contains([Attribute], "QTY") then [Attribute] else if [Attribute] = "ORIGINAL BALANCE" then [Attribute] else null),
    ReplacedValueQTY = Table.ReplaceValue(AddedCondColType,"QTY ","",Replacer.ReplaceText,{"Type"}),
    #"Split Column by Character Transition" = Table.SplitColumn(ReplacedValueQTY, "Type", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Type.1", "Type.2"}),
    RemovedColumnsTypeNo = Table.RemoveColumns(#"Split Column by Character Transition",{"Type.2"}),
    RenamedColumnsType = Table.RenameColumns(RemovedColumnsTypeNo,{{"Type.1", "Type"}}),
    AddedCondColQty = Table.AddColumn(RenamedColumnsType, "Qty", each if [Type] = "RECEIVED" then -1 * [Value] else if Text.StartsWith([Attribute], "QTY") then [Value] else null),
    #"Filled Down" = Table.FillDown(AddedCondColQty,{"Date", "InvoiceNo"}),
    FilledUpBalance = Table.FillUp(#"Filled Down",{"Balance"}),
    FilteredRowsNullType = Table.SelectRows(FilledUpBalance, each [Type] <> null and [Type] <> ""),
    #"Removed Columns" = Table.RemoveColumns(FilteredRowsNullType,{"Attribute", "Value", "Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ITEM #", "AM SNACKS", "Date", "InvoiceNo", "Type", "Qty", "Balance"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"ITEM #", Int64.Type}, {"AM SNACKS", type text},  {"Date", type date}, {"InvoiceNo", Int64.Type}, {"Qty", Int64.Type}, {"Type", type text}, {"Balance", Int64.Type}})
in
    #"Changed Type"
 
Upvote 0
Are you looking for the output to look something like this ?

20241112 PQ Power Query Unpivot messy BORUCH.xlsm
ABCDEFG
1ITEM #AM SNACKSDateInvoiceNoTypeQtyBalance
21apples6/09/2023ORIGINAL BALANCE8
31apples2/11/2023ORDERED7583
41apples19/11/20239999RECEIVED-1073
51apples19/11/2023123RECEIVED-5023
62oranges6/09/2023123ORIGINAL BALANCE-34
72oranges2/11/2023123ORDERED500466
82oranges19/11/20238888RECEIVED-40066
92oranges19/11/2023456RECEIVED-606
Unpivot


I did this using mostly just the UI in Power Query (which I see you have used in the past).
The resulting code is below, I am sure that someone using M can do it in much less code.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ITEM #", "AM SNACKS"}, "Attribute", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 1, 1, Int64.Type),
    AddedCondColDate = Table.AddColumn(#"Added Index", "Date", each if Text.EndsWith([Attribute], "DATE") then [Value] else null),
    AddedCondColInvNo = Table.AddColumn(AddedCondColDate, "InvoiceNo", each if Text.StartsWith([Attribute], "INVOICE") then [Value] else null),
    AddedCondColBalance = Table.AddColumn(AddedCondColInvNo, "Balance", each if Text.Contains([Attribute], "BALANCE") and not Text.Contains([Attribute], "DATE") then [Value] else null),
    AddedCondColType = Table.AddColumn(AddedCondColBalance, "Type", each if Text.Contains([Attribute], "QTY") then [Attribute] else if [Attribute] = "ORIGINAL BALANCE" then [Attribute] else null),
    ReplacedValueQTY = Table.ReplaceValue(AddedCondColType,"QTY ","",Replacer.ReplaceText,{"Type"}),
    #"Split Column by Character Transition" = Table.SplitColumn(ReplacedValueQTY, "Type", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Type.1", "Type.2"}),
    RemovedColumnsTypeNo = Table.RemoveColumns(#"Split Column by Character Transition",{"Type.2"}),
    RenamedColumnsType = Table.RenameColumns(RemovedColumnsTypeNo,{{"Type.1", "Type"}}),
    AddedCondColQty = Table.AddColumn(RenamedColumnsType, "Qty", each if [Type] = "RECEIVED" then -1 * [Value] else if Text.StartsWith([Attribute], "QTY") then [Value] else null),
    #"Filled Down" = Table.FillDown(AddedCondColQty,{"Date", "InvoiceNo"}),
    FilledUpBalance = Table.FillUp(#"Filled Down",{"Balance"}),
    FilteredRowsNullType = Table.SelectRows(FilledUpBalance, each [Type] <> null and [Type] <> ""),
    #"Removed Columns" = Table.RemoveColumns(FilteredRowsNullType,{"Attribute", "Value", "Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ITEM #", "AM SNACKS", "Date", "InvoiceNo", "Type", "Qty", "Balance"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"ITEM #", Int64.Type}, {"AM SNACKS", type text},  {"Date", type date}, {"InvoiceNo", Int64.Type}, {"Qty", Int64.Type}, {"Type", type text}, {"Balance", Int64.Type}})
in
    #"Changed Type"
hi
yes that's basically it
I would like one more change, that if lets say column J cell J2, in my original example, if its blank, i still want to show that in my final table as another row ,with type received zero with the balance whatever is in the net column cell which in my case would still be 83.
 
Upvote 0
What would be in columns H & I when J is blank ?
the same info that's there ,its one big receiving with one receiving date, we just happen to have received the oranges and not the apples
and actually the invoice numbers in my case are also the same there was no reason why i put different invoice numbers since it was one receiving but that point is irrelevant for what i want
 
Upvote 0

Forum statistics

Threads
1,223,589
Messages
6,173,227
Members
452,505
Latest member
Neeraj1990

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