I am extracting the CSV data through by PowerQuery by giving an Example shown in the picture below;
I would like to do it through PowerQuery M language, or by python could anyone help with this?
ProductKey OrderDateKey DueDateKey ShipDateKey CustomerKey PromotionKey CurrencyKey SalesTerritoryKey SalesOrderNumber SalesOrderLineNumber RevisionNumber OrderQuantity UnitPrice ExtendedAmount UnitPriceDiscountPct DiscountAmount ProductStandardCost TotalProductCost SalesAmount TaxAmt Freight CarrierTrackingNumber CustomerPONumber OrderDate DueDate ShipDate
535 20140101 20140113 20140108 11051 1 100 9 SO74253 1 1 1 24.99 24.99 0 0 9.3463 9.3463 24.99 1.9992 0.6248 1/01/2014 0:00 13/01/2014 0:00 8/01/2014 0:00
528 20140101 20140113 20140108 11051 1 100 9 SO74253 2 1 1 4.99 4.99 0 0 1.8663 1.8663 4.99 0.3992 0.1248 1/01/2014 0:00 13/01/2014 0:00 8/01/2014 0:00
222 20140101 20140113 20140108 11051 1 100 9 SO74253 3 1 1 34.99 34.99 0 0 13.0863 13.0863 34.99 2.7992 0.8748 1/01/2014 0:00 13/01/2014 0:00 8/01/2014 0:00
CodePudding user response:
Try the following:
let
Lines = Lines.FromBinary(File.Contents("<path>")),
UnquoteLines = List.Transform(Lines, each Text.Trim(_, "#(0022)")),
CombinedLines = Text.Combine(UnquoteLines, "#(cr)#(lf)"),
Source = Csv.Document(CombinedLines)
in
Source
This removes the beginning and ending quotes from each line before combining them again and sending them off to Csv.Document
. Splitting the steps this way retains compatibility with the query settings editor for the first and last step (for example, if you need to change the encoding, or the CSV delimiter).