Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
The Definitive Guide to Power Query (M)

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

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781835089729
Pages 758 pages
Edition 1st Edition
Languages
Authors (3):
Gregory Deckler Gregory Deckler
Profile icon Gregory Deckler
Rick de Groot Rick de Groot
Profile icon Rick de Groot
Melissa de Korte Melissa de Korte
Profile icon Melissa de Korte
View More author details

Table of Contents (19) Chapters

Preface Introducing M Working with Power Query/M Accessing and Combining Data Understanding Values and Expressions Understanding Data Types Structured Values Conceptualizing M Working with Nested Structures Parameters and Custom Functions Dealing with Dates, Times, and Durations Comparers, Replacers, Combiners, and Splitters Handling Errors and Debugging Iteration and Recursion Troublesome Data Patterns Optimizing Performance Enabling Extensions Other Books You May Enjoy
Index

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 2024 Publisher: Packt ISBN-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.
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 €14.99/month. Cancel anytime}