Forum Discussion
Unable to get this result when I copy code into another query! Code here is in PROPER format!!
Like you mentioned - we do not see the data. I just delete some part of code and edited few steps. Try this:
Tip: I think that you do not need all columns. Instead of reordering them you can hold CTRL then start clicking to column headers continuously. When you select all wanted columns, right click on one of selected column header and choose REMOVE OTHER COLUMNS option. This will remove non-selected columns and reorder them the way you were choosing them.
let
Source = Csv.Document(File.Contents("C:\Users\roger\Downloads\orders.csv"),[Delimiter=",", Columns=118, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Replaced Value" = Table.ReplaceValue(#"Promoted Headers"," ","",Replacer.ReplaceText,{"Telephone number (delivery)"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value","+","00",Replacer.ReplaceText,{"Telephone number (delivery)"}),
#"Renamed Columns" = Table.RenameColumns(#"Replaced Value2",{{"Full name (delivery)", "Recipient Name"}, {"Address line 1 (delivery)", "Recipient Address Line 1"}, {"Address line 2 (delivery)", "Recipient Address Line 2"}, {"County (delivery)", "Recipient Address Line 3 (County)"}, {"Town / city (delivery)", "Recipient Town"}, {"Postcode (delivery)", "Recipient Postcode"}, {"Telephone number (delivery)", "Recipient Mobile Phone"}, {"Email address", "Recipient Email Address"}, {"Shipping Weight", "Weight"}, {"Order #", "Reference Number"}}),
#"Uppercased Text" = Table.TransformColumns(#"Renamed Columns",{{"Recipient Town", Text.Upper, type text}}),
#"Split Column by Position" = Table.SplitColumn(#"Uppercased Text", "Safe place", Splitter.SplitTextByRepeatedLengths(25), {"Special Instructions 1", "Special Instructions 2", "Special Instructions 3", "Special Instructions 4"}),
#"Added Conditional Column" = Table.AddColumn(#"Split Column by Position", "Enhanced Compensation", each if [Payment total] <= 100 then "JCM0" else if [Payment total] <= 500 then "JCM1" else if [Payment total] <= 1000 then "JCM2" else if [Payment total] <= 1500 then "JCM3" else if [Payment total] <= 2000 then "JCM4" else if [Payment total] <= 2500 then "JCM5" else "JCM5"),
#"Replaced Value3" = Table.ReplaceValue(#"Added Conditional Column","",null,Replacer.ReplaceValue,{"Company name (delivery)"}),
#"Added Conditional Column1" = Table.AddColumn(#"Replaced Value3", "Recipient Business Name", each if [#"Company name (delivery)"] = null then [Recipient Name] else [#"Company name (delivery)"]),
#"Reordered Columns" = Table.ReorderColumns(#"Added Conditional Column1",{"Recipient Business Name", "Recipient Name", "Recipient Address Line 1", "Recipient Address Line 2", "Recipient Address Line 3 (County)", "Recipient Postcode", "Recipient Town", "Recipient Mobile Phone", "Recipient Email Address", "Special Instructions 1", "Special Instructions 2", "Special Instructions 3", "Special Instructions 4", "Reference Number", "Enhanced Compensation", "Weight", "Length", "Width", "Height", "Channel", "Channel order #", "Invoice #", "Order date", "Invoice date", "Due date", "Delivery date", "Despatch date", "Status", "Custom status", "Paid", "Paid on", "Placed by", "Completed on", "Completed by", "Allow contact", "User group", "Account ID", "Title", "First name", "Last name", "Full title", "Full name", "Company name", "Address line 1", "Address line 2", "Town / city", "County", "Postcode", "Country", "Country code", "Telephone number", "VAT number", "EORI number", "Facebook ID", "Delivery address", "Company name (delivery)", "Title (delivery)", "First name (delivery)", "Last name (delivery)", "Full title (delivery)", "Country (delivery)", "Country code (delivery)", "Currency code", "VAT rate", "Payment method", "Payment ID", "Voucher code", "Voucher total", "Product lines", "Product SKU", "Product parent", "Product bar code", "Product part number", "Product variant", "Product category", "Product brand", "Product supplier", "Product drop shipper", "Product intangible", "Product file", "Product file group", "Product bundle", "Product bundled", "Product gift voucher", "Product weight", "Product commodity code", "Product country of origin", "Product quantity", "Product warehouse location", "Product frequency", "Product instalments", "Product VAT rate", "Product VAT value", "Product price", "Product subtotal", "Order subtotal", "Discount total", "Coupon code", "Coupon total", "Weight total", "Shipping method", "Shipping VAT rate", "Shipping VAT value", "Shipping total", "Order VAT", "DDP duties", "DDP fees", "DDP taxes", "Order total", "Refunded total", "IP address", "Device type", "Site version", "Affiliate", "Referring domain", "Referring search", "Customer comments", "Admin comments", "Additions", "Product list", "Product full", "Product title", "Payment total"})
in
#"Reordered Columns"
WOW! That's such a great tip.
I've found it quite labourious to reorder.
You are right I do not need all columns.
I am slowly but surely gaining confidence now. Just this morning I was going to post another problem as I got an expression error
But instead I looked at the code and tried to figure out what was wrong.
This line had the number 5 in it so I changed it to 1 and retested and it resolved the error then I changed it to 0.
| = #"Added Custom1"{0}[Custom] |
You don't know how happy this makes me to actually be learning stuff like this at my age!
You are an absolute diamond helping people out as you do. Everyone on here is just great.
I glad I can self-help a little now and I can only grow I think.
Last night I broke down the two queries to split between two worksheets, one for box sizes over 300 cm girth and one for box sizes below. That in itself is life changing in simplifying my workload and ensuring errors are not made.
So thanks again and apologies for being so dumb the other week in not being able to work out how to post sample data properly even.
I hope I finally got it right this time!
Very best wishes.