Reader small image

You're reading from  The Definitive Guide to Power Query (M)

Product typeBook
Published inMar 2024
Reading LevelBeginner
PublisherPackt
ISBN-139781835089729
Edition1st Edition
Languages
Right arrow
Authors (3):
Gregory Deckler
Gregory Deckler
author image
Gregory Deckler

Greg Deckler is a 7-time Microsoft MVP for Data Platform and an active blogger and Power BI community member, having written over 6,000 solutions to community questions. Greg has authored many books on Power BI, including Learn Power BI 1st and 2nd Editions, DAX Cookbook, Power BI Cookbook 2nd Edition and Mastering Power BI 2nd Edition. Greg has also created several external tools for Power BI and regularly posts video content to his YouTube channels, Microsoft Hates Greg and DAX For Humans.
Read more about Gregory Deckler

Rick de Groot
Rick de Groot
author image
Rick de Groot

Rick de Groot was born in the Netherlands and has been working in BI for more than 14 years. He went freelance in 2016 and now works as an independent Power BI consultant. On his mission to make Power BI more accessible, he started two blogs: BI Gorilla and PowerQuery. how, and a YouTube channel sharing Power Query and Power BI content. His commitment to offering free content through multiple platforms has led him to earning the Microsoft Data Platform MVP award for two consecutive years.
Read more about Rick de Groot

Melissa de Korte
Melissa de Korte
author image
Melissa de Korte

Melissa de Korte's approach to facing challenges is fueled by relentless curiosity. She is a dedicated community member and content creator. Her portfolio includes blogs, tutorials, courses, and webinars, that make Power Query M more accessible and useful for all. Behind her professional persona lies a genuine dedication to empowering others through education and knowledge sharing, and a desire to encourage professionals to embrace the potential of Power Query, M.
Read more about Melissa de Korte

View More author details
Right arrow

Null Values

A null value is used to represent the absence of a value, or a value of indeterminate or unknown state (i.e., in the case of a missing value).

Structure

A null value is written using the literal null.It is critical to note that null is different from 0. The former is the absence of a value, while 0 is a specific numerical value, just like 1 or 732.

Examples

if [Value] = null then “NA” else [Value]

Special Considerations

  • Equality Comparisons – Null has some unique properties with regard to how expressions involving the quality operator are evaluated. For example, null is only strictly equal to itself.
null = null    returns true
null = true     returns false
null = false    returns false
null <= null     returns null
null >= null     returns null
null <> null  returns null
null <...

Number Values

Number values in M are used to express numeric amounts and for mathematical calculations. While the concept of “a number” is familiar to everyone, number values in M have the most varied literal forms of any value kind.

Structure and Examples

All of the expressions below represent valid number values in M:

Figure 3.6: Number Values in M

Text Values

In M, text values are sequences of characters, which are used to represent text data.

Structure

Text values in M are indicated by “ “

Examples

“Basketball”
“23”
“November 9, 1993”

List Values

A list is a series of values. In M, a single column of values is a list, and lists can contain any type of primitive or structured values.

Structure

Lists are initiated by curly brackets “{ }”

Examples

{ 1, 2, 3 }
{ “Cat”, “Dog”, “Monkey” }
{ { 1, 2, 3 }, { “Cat”, “Dog”, “Monkey” } }

Record Values

A record is a named list of values. You also can think of a record as a single row in a table, where each field in the row has a column name and a value. Like lists, records can contain either primitive or structured values.

Structure

Records are initiated by square brackets “[ ]”

Examples

[Planet = “Earth”,  MilesFromSun = 92960000, AdjacentPlanets = { “Venus”, “Mars” }]
Figure 3.7: Creation of a record in M, also showing the values within a nested list

Table Values

A table is a structured value composed of: 1) Rows, where each row represents a record; 2) Columns, where each column represents a field of a record and has a specific datatype; and 3) Headers, which are the names of each column.Tables can be created in many different ways in M, including using the #table constructor, or from values, lists, records, columns or rows using the appropriate M function.

Structure

table(
columns as any,
rows as any,
) as any

Examples

let
    Source = #table(
        type table [ProductID = text, ProductQuantity = number, Column3 = date],
        {
            {“P001”, 10, #date(2023, 8, 13)},
            {“P002”, 25, #date(2023, 8, 14)},
            {“P003”, 30, #date(2023, 8, 15)}
        }
    )
in
    Source

There are many ways to construct tables using #table, as well as other functions that creates tables from other kinds of primitive and structured value. These methods will be addressed in...

Function Values

Function values are those that when invoked with a set of input values (i.e., arguments) produce a new value.

Structure

In M, functions are specified by listing the input parameters of the function in parentheses, then the “goes to” operator =>, then the expression that defines the function.

Examples

Concatenator = (parameter1, parameter2) => (parameter1 & parameter2)
DifferentDistinct = (x) => List.Difference(x,List.Distinct(x))

Special Considerations

  • Flexibility and Power – Functions can be assigned to variables, passed as arguments, and returned from other functions, making them some of the most versatile and powerful kinds of values in M.
  • Importance...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Definitive Guide to Power Query (M)
Published in: Mar 2024Publisher: PacktISBN-13: 9781835089729
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Gregory Deckler

Greg Deckler is a 7-time Microsoft MVP for Data Platform and an active blogger and Power BI community member, having written over 6,000 solutions to community questions. Greg has authored many books on Power BI, including Learn Power BI 1st and 2nd Editions, DAX Cookbook, Power BI Cookbook 2nd Edition and Mastering Power BI 2nd Edition. Greg has also created several external tools for Power BI and regularly posts video content to his YouTube channels, Microsoft Hates Greg and DAX For Humans.
Read more about Gregory Deckler

author image
Rick de Groot

Rick de Groot was born in the Netherlands and has been working in BI for more than 14 years. He went freelance in 2016 and now works as an independent Power BI consultant. On his mission to make Power BI more accessible, he started two blogs: BI Gorilla and PowerQuery. how, and a YouTube channel sharing Power Query and Power BI content. His commitment to offering free content through multiple platforms has led him to earning the Microsoft Data Platform MVP award for two consecutive years.
Read more about Rick de Groot

author image
Melissa de Korte

Melissa de Korte's approach to facing challenges is fueled by relentless curiosity. She is a dedicated community member and content creator. Her portfolio includes blogs, tutorials, courses, and webinars, that make Power Query M more accessible and useful for all. Behind her professional persona lies a genuine dedication to empowering others through education and knowledge sharing, and a desire to encourage professionals to embrace the potential of Power Query, M.
Read more about Melissa de Korte