对于Power Query / PowerBI中的M,应该使用哪种语法设置数据类型?A)type text
(或type logical
,type date
等)B)Text.Type
(或Logical.Type
,Date.Type
等)
现在选项B存在,是否有任何理由使用选项A语法?我尝试阅读Power Query M language specification的第5章,但找不到清晰的答案。
这里是使用Table.AddColumn的一个示例(尽管数据类型随处可见):
let
OldTable = #table({"Col1"},{{"This column"}}),
fMyFunc = (paramText as text ) as text => let returnText = paramText & "_new" in returnText,
NewTable = Table.AddColumn(OldTable, "NewCol", each "Sample", Text.Type),
NewerTable = Table.AddColumn(NewTable, "NewerCol", each fMyFunc([NewCol]), Text.Type)
in
NewerTable
我相信引入选项B只是为了标准化类型定义;例如,有Int64.Type
,但没有type Int64
。因此,我的问题的答案可能是“完全没有关系”。但是,如果一个选择似乎是对未来的共识,那么我现在就开始在代码中保持一致。
我同意,除了从样式角度来看,这没有关系。
正如您所提到的,像Int64.Type
那样的非原始类型不能像type Int64
那样写为type text
,因此,如果要在原始类型和非原始类型之间保持样式一致,那么您可以想要选项B。
链接的文档的第48和49页上列出的原始类型是:
type null
,对空值进行分类type logical
,将值true和false进行分类type number
,对数字值进行分类type time
,对时间值进行分类type date
,对日期值进行分类type datetime
,对日期时间值进行分类type datetimezone
,对datetimezone值进行分类type duration
,对持续时间值进行分类type text
,对文本值进行分类type binary
,对二进制值进行分类type type
,对类型值进行分类。type list
,对列表值进行分类type record
,对记录值进行分类type table
,对表值进行分类type function
,对功能值进行分类type anynonnull
,将所有值分类,不包括空值