List.Numbers

Updated on

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
ArgumentAttributeDescription
StartThe start value of the sequence.
CountThe number of values to generate.
IncrementOptionalThe 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, -4 }

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.

Learn more about List.Numbers in the following articles:

Other functions related to List.Numbers are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/list-numbers