List.Numbers is a Power Query M function that creates a list of numbers given an initial value, count, and optional increment value. The function returns a list of numbers incremented by the specified or default increment value.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
List.Numbers(
start as number,
count as number,
optional increment as nullable number,
) as list
Argument | Attribute | Description |
---|---|---|
Start | The start value of the sequence. | |
Count | The number of values to generate. | |
Increment | Optional | The increment value of each step. |
Description
The List.Numbers
function, at its core, creates a list of numbers. It has a flexible structure allowing you to define where the list starts, how long it is (the count), and the increments between numbers.
By default, if the increment is not specified, the function progresses with an increment of 1.
Examples
Let’s dive into a few examples on how to use the List.Numbers function.
Creating Consecutive Numbers
Imagine a scenario where you need five consecutive numbers, initiating from 1:
List.Numbers( 1, 5 ) // Returns { 1, 2, 3, 4, 5 }
To be clearer about your intentions, the increment can be explicitly set, even if it’s the default value of 1:
List.Numbers( 1, 5, 1 ) // Returns { 1, 2, 3, 4, 5 }
Specifying Different Increments
The function supports custom increments. For a list of 8 numbers beginning from 1, but jumping up by 2 each time:
List.Numbers( 1, 8, 2 ) // Returns { 1, 3, 5, 7, 9, 11, 13, 15 }
If you desire smaller increments, like 0.1:
List.Numbers( 1, 5, 0.1 ) // Returns { 1, 1.1, 1.2, 1.3, 1.4, 1.5 }
Generating Numbers in Reverse
The function isn’t restricted to just forward increments. You can move backward too.
Starting from 1, with a decrement of 1 for 5 numbers:
List.Numbers( 1, 5, -1 ) // Returns { 1, 0, -1, -2, -3 }
Similarly, if you start from 5 and move backward:
List.Numbers( 5, 5, -1 ) // Returns { 5, 4, 3, 2, 1 }
The List.Numbers
function is a great way to generate a list of numbers. By understanding and experimenting with its parameters, you can produce a wide range of number sequences to fit your data needs.
Related articles
Learn more about List.Numbers in the following articles:
- Creating Sequences in Power Query
Create Sequences in Power Query and Simplify your Code. Learn how to generate series of numbers, text, symbols, and dates with simple functions. » Read more - Create Date Table or Calendar in Power Query M
Learn how to create a dynamic calendar table in Power Query’s M language. Build your custom columns and claim your free Date Table Script. » Read more - Lists in Power Query M / List Functions (200+ Examples)
The complete guide to Lists in Power Query M. Learn from practical examples and master Power Query’s most powerful List functions. » Read more - Lists in Power Query M / List Functions (200+ Examples)
The complete guide to Lists in Power Query M. Learn from practical examples and master Power Query’s most powerful List functions. » Read more
Related functions
Other functions related to List.Numbers are:
- List.Accumulate
- List.DateTimeZones
- List.DateTimes
- List.Dates
- List.Durations
- List.Generate
- List.Random
- List.Times
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy