Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
xzmiche
Resolver I
Resolver I

How to get delivery date for order table from inventory table and get updated inventory?

I cannot find a Power Query solution to get delivery date for order table from inventory table and get updated inventory. Can anyone help me on that?

 

My data:

Input:

In_Order_Table:

Order IdProduct
1p1
2p2
3p1
4p3
5p2

In_Inventory_Table:

ProductDateQty
p101-May1
p102-May2
p201-May2
p303-May1
p103-May2

Output:

Out_Order_Table:

Order IdProductDelivery Date
1p101-May
2p201-May
3p102-May
4p303-May
5p201-May

Out_Inventory_Table:

ProductDateQty
p101-May0
p102-May1
p201-May0
p303-May0
p103-May2
1 ACCEPTED SOLUTION

Hi @xzmiche ,

If cannot add product id in "In_Inventory_Table", still need a reference column like an index column to query.

For "In_Order_Table":

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUSowVIrViVYyAjGNwExjhKgJiGkMZppCFcQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order Id" = _t, Product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Id", Int64.Type}, {"Product", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1), type table [Order Id=nullable number, Product=nullable text]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Order Id","Index"}, {"Order Id","Index"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Data",{{"Product", type text}, {"Order Id", Int64.Type}, {"Index", Int64.Type}})
in
    #"Changed Type1"

For "In_Inventory_Talbe":

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKjBU0lEyMNT1TawEMgyVYnVgYkZQMSOImBGyOqiYMUjMGIteY4S6WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Date = _t, Qty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Date", type date}, {"Qty", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1,Int64.Type), type table [Product=nullable text, Date=nullable date, Qty=nullable number]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Date", "Qty","Index"}, {"Date", "Qty","Index"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Data",{{"Index", Int64.Type}})
in
    #"Changed Type1"

"Out_Order_Table" query:

let
    Source = Table.NestedJoin(In_Order_Table, {"Product", "Index"}, In_Inventory_Table, {"Product", "Index"}, "In_Inventory_Table", JoinKind.LeftOuter),
    #"Sorted Rows" = Table.Sort(Source,{{"Order Id", Order.Ascending}}),
    #"Expanded In_Inventory_Table" = Table.ExpandTableColumn(#"Sorted Rows", "In_Inventory_Table", {"Date"}, {"In_Inventory_Table.Date"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded In_Inventory_Table",null,List.Min(#"Expanded In_Inventory_Table"[In_Inventory_Table.Date]),Replacer.ReplaceValue,{"In_Inventory_Table.Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"In_Inventory_Table.Date", "Delivery Date"}})
in
    #"Renamed Columns"

11.png

 "Out_Inventory_table" query:

let
    Source = Table.NestedJoin(In_Inventory_Table, {"Product", "Date"}, Out_Order_Table, {"Product", "Delivery Date"}, "Out_Order_Table", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each [Qty] - Table.RowCount([Out_Order_Table])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Qty", "Index", "Out_Order_Table"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Qty"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Product", type text}, {"Date", type date}, {"Qty", Int64.Type}})
in
    #"Changed Type"

 22.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-yingjl
Community Support
Community Support

Hi @xzmiche ,

If the Delivery Date column is added based on the In_Order_Table, you can try this query on the In_Inventory_Table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKjBU0lEyMNT1TawEMgyVYnVgYkZQMSOImBGyOqiYMUjMGIteY4S6WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Date = _t, Qty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Date", type date}, {"Qty", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Product", "Date"}, In_Order_Table, {"Product", "Delivery Date"}, "In_Order_Table", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each [Qty] - Table.RowCount([In_Order_Table]),Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Qty", "In_Order_Table"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Qty"}})
in
    #"Renamed Columns"

1.png2.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Yingjie!

 

Your answer is exactly the question 2 based on table Out_Order_Table and In_Inventory_Table to generate Out_Inventory_Table. Would you please help on studying question1 to generate Out_Order_Table based on In_Order_Table and In_Inventory_Table?

 

Hi @xzmiche ,

If just based on the source two tables, you need to add a column 'oder id' in 'In_Inventory_Table' in order to combine them based on the id like this:

4.png

Since there is no clear logic about the null date after merging tables, need to define a logic manually in the query like this to get 'Out_Order_Table':

let
    Source = Table.NestedJoin(In_Order_Table, {"Order Id", "Product"}, In_Inventory_Table, {"Order Id", "Product"}, "In_Inventory_Table", JoinKind.LeftOuter),
    #"Expanded In_Inventory_Table" = Table.ExpandTableColumn(Source, "In_Inventory_Table", {"Date"}, {"In_Inventory_Table.Date"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded In_Inventory_Table",null,List.Min(#"Expanded In_Inventory_Table"[In_Inventory_Table.Date]),Replacer.ReplaceValue,{"In_Inventory_Table.Date"}),
    #"Renamed Columns" = Table.RenameColumns(#"Replaced Value",{{"In_Inventory_Table.Date", "Delivery Date"}})
in
    #"Renamed Columns"

'Out_Inventory_Table' query:

let
    Source = Table.NestedJoin(In_Inventory_Table, {"Product", "Date"}, Out_Order_Table, {"Product", "Delivery Date"}, "Out_Order_Table", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each [Qty] - Table.RowCount([Out_Order_Table])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Qty", "Order Id", "Out_Order_Table"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Qty"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Product", type text}, {"Date", type date}, {"Qty", Int64.Type}})
in
    #"Changed Type"

5.png6.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Yingjie,

 

Sorry to confuse you! Let me clarify my logic as below:

1. we select one row from "In_Order_Table"

2. find earliest date in "In_Inventory_Talbe"

3. put this date in "Out_Order_Table"

4. at same time we reduce qty in "Out_Inventory_table"

5. repeat 1-4 until all orders dealed

 

By above steps, we can get "Out_Order_Table" and "Out_Inventory_Table". So we cannot add product id in "In_Inventory_Table".

xzmiche_0-1629159411562.png

 

 

Hi @xzmiche ,

If cannot add product id in "In_Inventory_Table", still need a reference column like an index column to query.

For "In_Order_Table":

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUSowVIrViVYyAjGNwExjhKgJiGkMZppCFcQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order Id" = _t, Product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Id", Int64.Type}, {"Product", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1), type table [Order Id=nullable number, Product=nullable text]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Order Id","Index"}, {"Order Id","Index"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Data",{{"Product", type text}, {"Order Id", Int64.Type}, {"Index", Int64.Type}})
in
    #"Changed Type1"

For "In_Inventory_Talbe":

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKjBU0lEyMNT1TawEMgyVYnVgYkZQMSOImBGyOqiYMUjMGIteY4S6WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Date = _t, Qty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Date", type date}, {"Qty", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1,Int64.Type), type table [Product=nullable text, Date=nullable date, Qty=nullable number]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Date", "Qty","Index"}, {"Date", "Qty","Index"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Data",{{"Index", Int64.Type}})
in
    #"Changed Type1"

"Out_Order_Table" query:

let
    Source = Table.NestedJoin(In_Order_Table, {"Product", "Index"}, In_Inventory_Table, {"Product", "Index"}, "In_Inventory_Table", JoinKind.LeftOuter),
    #"Sorted Rows" = Table.Sort(Source,{{"Order Id", Order.Ascending}}),
    #"Expanded In_Inventory_Table" = Table.ExpandTableColumn(#"Sorted Rows", "In_Inventory_Table", {"Date"}, {"In_Inventory_Table.Date"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded In_Inventory_Table",null,List.Min(#"Expanded In_Inventory_Table"[In_Inventory_Table.Date]),Replacer.ReplaceValue,{"In_Inventory_Table.Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"In_Inventory_Table.Date", "Delivery Date"}})
in
    #"Renamed Columns"

11.png

 "Out_Inventory_table" query:

let
    Source = Table.NestedJoin(In_Inventory_Table, {"Product", "Date"}, Out_Order_Table, {"Product", "Delivery Date"}, "Out_Order_Table", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each [Qty] - Table.RowCount([Out_Order_Table])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Qty", "Index", "Out_Order_Table"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Qty"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Product", type text}, {"Date", type date}, {"Qty", Int64.Type}})
in
    #"Changed Type"

 22.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Excellent! That really solved my concerns by adding 2 indexes in 2 input tables.

lbendlin
Super User
Super User

Power BI is not an inventory management tool.  You may want to do these computations in the source system.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors