Excel · Power Query

The M Behind The New Power Query Data Types In Excel

The big news this week – at least for me – was the release of the new Power Query data types to the Excel insiders channel. You can read all about it here:

https://insider.office.com/en-us/blog/power-query-data-types-in-excel

They’re the latest manifestation of Excel linked data types; cool things are also happening with them and Power BI featured tables too.

The announcement blog post explains pretty much everything you can do right now with Power Query data types but I was curious about the M code that is used to create them. Here’s an example query that takes this source table:

…and creates this Power Query data type:

let
  Source = #table(
      type table[
        Fruit = text, 
        Colour = text, 
        Sales = number
      ], 
      {
        {"Apples", "Green", 10}, 
        {"Lemons", "Yellow", 20}, 
        {"Strawberries", "Red", 30}
      }
    ),
  #"Created data type"
    = Table.CombineColumnsToRecord(
        Source, 
        "Data type", 
        {"Fruit", "Colour", "Sales"}, 
        [DisplayNameColumn = "Fruit", TypeName
          = "Excel.DataType"]
      )
in
  #"Created data type"

The magic happens with the #”Created data type” step and the Table.CombineColumnsToRecord function; so Power Query data types are basically columns that contain record values with (I guess, I need to check) some extra metadata.

4 thoughts on “The M Behind The New Power Query Data Types In Excel

  1. Hi Chris! Thanks for this article! Can I ask you about the performance and final size? Is this method more efficient both in speed and size? Have a good day!

  2. > The magic happens with the #”Created data type” step and the Table.CombineColumnsToRecord function; so Power Query data types are basically columns that contain record values with (I guess, I need to check) some extra metadata.

    If anyone is interested, the metadata is along these lines:

    #table(
    type table [
    ID = number,
    Combined = (type [A=any, B=any] meta [Documentation.TypeName=”Excel.DataType”])
    ],
    {
    { 1, [A = “hi”, B = “bye”] meta [Documentation.DisplayName = “hello world”]}
    }
    )

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.