电源查询,拆分列日期和时间不起作用

时间:2018-10-24 03:49:47

标签: powerquery

请帮助我如何在原始文件源中拆分列日期和时间dd-mmm-yyyy(双空格)hh:mm:ss xls sources data

问题是所有列的提取日期仅(我也需要时间),请看图片

Query Result

这是代码

let
    Source = Excel.Workbook(File.Contents("D:\IP_Enquiry_Result_20181015_082020.xls"), null, true),
    #"Enquiry Result1" = Source{[Name="Enquiry Result"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(#"Enquiry Result1",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", type text}, {"Column13", type text}, {"Column14", type text}, {"Column15", type text}, {"Column16", type text}, {"Column17", type text}, {"Column18", type text}, {"Column19", type text}, {"Column20", type text}, {"Column21", type text}, {"Column22", type text}, {"Column23", type text}, {"Column24", type text}, {"Column25", type text}, {"Column26", type text}, {"Column27", type text}, {"Column28", type text}, {"Column29", type text}, {"Column30", type text}, {"Column31", type text}, {"Column32", type text}, {"Column33", type text}, {"Column34", type text}, {"Column35", type text}, {"Column36", type text}, {"Column37", type text}, {"Column38", type text}, {"Column39", type text}, {"Column40", type text}, {"Column41", type text}, {"Column42", type text}, {"Column43", type text}, {"Column44", type text}, {"Column45", type text}, {"Column46", type text}, {"Column47", type text}, {"Column48", type text}, {"Column49", type text}, {"Column50", type text}, {"Column51", type text}, {"Column52", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Column47] <> null)),
    #"Promoted Headers" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true])
in
    #"Promoted Headers"

2 个答案:

答案 0 :(得分:0)

我相信,当您将电子表格的表作为源带入PowerQuery时,它将把日期和时间之间的双倍空格更改为一个空格。至少,这就是它为我所做的。然后,您需要做的就是选择具有要拆分的日期和时间的列,然后单击 Transform > Split Column > 按分隔符>,然后将-Custom-更改为 Space ,然后单击最左定界符的单选按钮,然后单击“确定”。 / p>

这就是代码的最终外观(我的表名为Table1,列名为DateTime):

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}}),
#"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type", {{"DateTime", type text}}, "en-US"), "DateTime", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"DateTime.1", "DateTime.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"DateTime.1", type date}, {"DateTime.2", type time}})
in
#"Changed Type1"

如果在将表放入时不能将双空格更改为单空格:而不是将-Custom-更改为 Space ,在-Custom-下面的框中键入两个空格(按两次空格键)。

答案 1 :(得分:-1)

我找到了使其出现的方法,它使用了Microsoft查询,一切都很好。 我尝试使用“用于ODBC驱动程序的MS OLE DB提供程序”,但无法替换excel源。
谢谢大家的帮助,祝您有美好的一天:)