Returned items not in sales list?

Status
Not open for further replies.

shophoney

Active Member
Joined
Jun 16, 2014
Messages
286
Hi,

I'm trying to either with POWER QUERY or DAX find a way to go through my list of sold items by invoice number and look for items returned that were never sold to the customer. The item could be sold to another customer which is fine. But I'm looking for returns that are not valid as the customer never purchased them.

Power Query would be better but Dax would be slower.

Any suggestions on how to do it? Iteration column in dax?

This is my POWER QUERY
let
Source = Sql.Database("server", "DB0001_230804114905"),
dbo_tblSale = Source{[Schema="dbo",Item="tblSale"]}[Data],
#"Filtered <1/31/22" = Table.SelectRows(dbo_tblSale, each [date] > #datetime(2022, 1, 31, 0, 0, 0)),
#"Expanded tblCustomer" = Table.ExpandRecordColumn(#"Filtered <1/31/22", "tblCustomer", {"name", "last_name"}, {"Customer First Name", "Customer Last Name"}),
#"Expanded tblEmployee" = Table.ExpandRecordColumn(#"Expanded tblCustomer", "tblEmployee", {"name"}, {"Employee"}),
#"Expanded tblSaleItem" = Table.ExpandTableColumn(#"Expanded tblEmployee", "tblSaleItem", {"affect_inv", "affect_total", "cost", "description", "note", "qty", "sku_no", "tblSaleDiscount", "unit_ext_best_price"}, {"affect_inv", "affect_total", "cost", "description", "note.Sale Item", "qty", "sku_no", "tblSaleDiscount", "unit_ext_best_price"}),
#"Expanded tblSaleDiscount" = Table.ExpandTableColumn(#"Expanded tblSaleItem", "tblSaleDiscount", {"disc_code", "amount"}, {"disc_code", "Discount Amount"}),
#"Filtered TRANS ONLY" = Table.SelectRows(#"Expanded tblSaleDiscount", each [trans_type] <> "0CLO" and [trans_type] <> "0CTP" and [trans_type] <> "0FLO" and [trans_type] <> "0LSS" and [trans_type] <> "0PIC" and [trans_type] <> "0COU"),
#"Grouped Rows" = Table.Group(#"Filtered TRANS ONLY", {"sale_link"}, {{"MIN UNITS", each List.Min([qty]), type nullable number}, {"ALL ROWS", each _, type table [sale_link=text, source_loc=text, loc_code=text, register_code=text, trans_no=number, register_type=text, link_journal=text, link_order=nullable text, date=datetime, time=datetime, trans_type=text, cashier=text, customer_code=nullable text, voided_by=nullable number, void_code=nullable text, suspended=nullable text, gr_no=nullable text, status=nullable text, sale_type_curr=text, dumped=logical, note=nullable text, Customer First Name=nullable text, Customer Last Name=nullable text, Employee=nullable text, tblGREntry=nullable record, tblJournal=nullable record, tblLocation=nullable record, tblOrder=nullable record, tblRegister=nullable record, sku_no=nullable number, affect_inv=nullable logical, affect_total=nullable logical, unit_ext_best_price=nullable number, cost=nullable number, qty=nullable number, description=nullable text, disc_code=nullable text, Discount Amount=nullable number, tblSaleRewards=table, tblSaleShipTo=table, tblSaleTax=table, tender_code=nullable text, amount=nullable number, tblVoid=nullable record, note.Sale Item]}}),
#"Added Conditional Column" = Table.AddColumn(#"Grouped Rows", "RETURN", each if [MIN UNITS] <= 0 then "RETURN" else "PURCHASE"),
#"Expanded ALL ROWS" = Table.ExpandTableColumn(#"Added Conditional Column", "ALL ROWS", {"source_loc", "loc_code", "register_code", "trans_no", "register_type", "link_journal", "link_order", "date", "time", "trans_type", "cashier", "customer_code", "voided_by", "void_code", "suspended", "gr_no", "status", "sale_type_curr", "dumped", "note", "Customer First Name", "Customer Last Name", "Employee", "tblGREntry", "tblJournal", "tblLocation", "tblOrder", "tblRegister", "sku_no", "affect_inv", "affect_total", "unit_ext_best_price", "cost", "qty", "description", "disc_code", "Discount Amount", "tblSaleRewards", "tblSaleShipTo", "tblSaleTax", "tblVoid", "note.Sale Item"}, {"source_loc", "loc_code", "register_code", "trans_no", "register_type", "link_journal", "link_order", "date", "time", "trans_type", "cashier", "customer_code", "voided_by", "void_code", "suspended", "gr_no", "status", "sale_type_curr", "dumped", "note", "Customer First Name", "Customer Last Name", "Employee", "tblGREntry", "tblJournal", "tblLocation", "tblOrder", "tblRegister", "sku_no", "affect_inv", "affect_total", "unit_ext_best_price", "cost", "qty", "description", "disc_code", "Discount Amount", "tblSaleRewards", "tblSaleShipTo", "tblSaleTax", "tblVoid", "note.Sale Item"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded ALL ROWS",{ {"date", type date}}),
#"Inserted CUSTOMER" = Table.AddColumn(#"Changed Type", "CUSTOMER", each Text.Combine({[Customer Last Name], [Customer First Name]}, ", "), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted CUSTOMER",{ "source_loc", "register_code", "register_type", "link_journal", "link_order", "time", "cashier", "gr_no", "sale_type_curr", "dumped", "Customer First Name", "Customer Last Name", "tblGREntry", "tblJournal", "tblLocation", "tblOrder", "tblRegister", "tblSaleRewards", "tblSaleShipTo", "tblSaleTax", "tblVoid", "MIN UNITS"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"note", "NOTE"}, {"description", "DESCRIPTION"}, {"cost", "COST"}, {"unit_ext_best_price", "RETAIL"}, {"sku_no", "SKU#"}, {"Discount Amount", "DISCOUNT AMOUNT"}, {"disc_code", "DISC CODE"}, {"Employee", "EMPLOYEE"}, {"date", "DATE"}, {"loc_code", "LOCATION"}, {"trans_no", "TRANS#"}, {"trans_type", "TRANS TYPE"}}),
#"Merged NOTES" = Table.CombineColumns(Table.TransformColumnTypes(#"Renamed Columns", {{"note.Sale Item", type text}}, "en-US"),{"NOTE", "note.Sale Item"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"NOTES"),
#"Capitalized Each Word" = Table.TransformColumns(#"Merged NOTES",{{"DESCRIPTION", Text.Proper, type text}, {"CUSTOMER", Text.Proper, type text}, {"NOTES", Text.Proper, type text}})
in
#"Capitalized Each Word"
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Duplicate to: Power Query looking for item not in list

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.

Also when posting code please use code tags (the M icon in the reply window) rather than posting it all in bold text.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,880
Messages
6,175,157
Members
452,615
Latest member
bogeys2birdies

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