For M in Power Query/ PowerBI, which syntax should I be using to set data types?
A) type text
(or type logical
, type date
, etc.)
B) Text.Type
( or Logical.Type
, Date.Type
, etc.)
Now that option B exists, is there any reason to ever use the option A syntax? I tried reading chapter 5 of the Power Query M language specification, but I couldn't find a clear answer.
Here is one example using Table.AddColumn (though data types show up everywhere):
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
I believe Option B was introduced just to standardize the type definitions; for example, there was Int64.Type
but not type Int64
. Thus, the answer to my question could be "It doesn't matter at all." But, if one option seems to be the consensus for the future, I'd rather start now with being consistent in my code.
I'd agree that it doesn't matter except from a stylistic perspective.
As you mentioned, non-primitive types like Int64.Type
can't be written as type Int64
like you can with type text
, so if you want to keep your style consistent between primitive and non-primitive types, then you want option B.
The primitive types listed on page 48 and 49 of the document you linked are:
type null
, which classifies the null valuetype logical
, which classifies the values true and falsetype number
, which classifies number valuestype time
, which classifies time valuestype date
, which classifies date valuestype datetime
, which classifies datetime valuestype datetimezone
, which classifies datetimezone valuestype duration
, which classifies duration valuestype text
, which classifies text valuestype binary
, which classifies binary valuestype type
, which classifies type values.type list
, which classifies list valuestype record
, which classifies record valuestype table
, which classifies table valuestype function
, which classifies function valuestype anynonnull
, which classifies all values excluding null