Search code examples
excelpowerbipowerquerym

M table using a predefined type per column


In the following M query:

let
    #"My Source" = Table.FromRecords({
        [Name="Jared Smith", Age=24],
        [Name = "Tom Brady", Age=44],
        [Name="Hello Tom", Age = null],
        [Name = "asdf", Age = "abc"]
    })
in
    #"My Source"

Why does "abc" not produce an error? Does PowerPivot use the "any" type unless the type is explicitly defined?

enter image description here


Solution

  • You can specify the type for each column using the #table function:

    let
        Source = #table(
            type table
                [
                    #"Name"=text,
                    #"Age"=number
                ], 
                {
                    {"Jared Smith", 24},
                    {"Tom Brady", 4},
                    {"Hello Tom", null},
                    {"asdf", "abc"}
                }
            )
    in
        Source