我试图通过添加带有日期/时间数据的自定义列(例如2021-09-01 18:00:00)来组合日期和时间。试图通过以下代码来实现这一点:
[date] and " " and [time]
但最后我得到了标题上的错误。我看不出公式栏有什么问题:
= Table.AddColumn(#"CreateTime naming", "Custom", each [date] and " " and [time])
在我对日期和时间做了非常相似的操作之前,我使用了与上面相同的代码短语结构,它起了作用。然后,我试着根据上述操作调整它,结果失败了。
我得到的错误消息是:
Expression.Error: We cannot convert the value #date(2021, 9, 2) to type Logical.
Details:
Value=2021-09-02
Type=[Type]
你能帮我解决这个问题吗?
发布于 2021-09-15 12:49:30
希望这次讨论能澄清我在评论中所写的内容。
使用的公式:
#"Added Custom" = Table.AddColumn(#"Changed Type", "datetime",
each [date] & [time])
我怀疑你是想用这样的方法:
each [date] & " " & [time])
这就是你在评论中提到的最后一个错误的原因。
Expression.Error: We cannot apply operator & to types Date and Text.
Details:
Operator=&
Left=9/1/2021
Right=
如果该问题与[Time]
有关,则错误将为:
Expression.Error: We cannot apply operator & to types Text and Time.
Details:
Operator=&
Left=
Right=1:15:00 PM
但是,&
运算符将将日期类型和时间类型加入到日期时间类型中。不需要进一步转换。
例如:
let
//data typed into a table
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkksSVXSUSrJzE1VitWJVrLUN9Q3MjAyBIoZGlsZmkIFjWCCZlYm5uhillamRkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
//data types set to date and time for the respective columns
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"date", type date}, {"time", type time}}),
//create a datetime column
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [date] & [time], type datetime)
in
#"Added Custom"
https://stackoverflow.com/questions/69184516
复制相似问题