GENERATESERIES DAX Function (Table manipulation)

Returns a table with one column, populated with sequential values from start to end.

Syntax

GENERATESERIES ( <StartValue>, <EndValue> [, <IncrementValue>] )
Parameter Attributes Description
StartValue

The start value of the column.

EndValue

The end value of the column.

IncrementValue Optional

The increment value of the column.

Return values

Table A table with a single column.

A single column table containing the values of an arithmetic series.
The name of the column is Value.

Remarks

When EndValue is less than StartValue, an empty table is returned.
IncrementValue must be a positive value.
The sequence stops at the last value that is less than or equal to EndValue.

» 1 related article

Examples

--  GENERATESERIES returns a list of values given the first
--  value, the last and the step.
EVALUATE 
    GENERATESERIES ( 1, 10, 1 )
    
EVALUATE 
    GENERATESERIES ( 5, 20, 5 )
    
EVALUATE 
    GENERATESERIES ( 0, 1, 0.1 )
Value
1
2
3
4
5
6
7
8
9
10
Value
5
10
15
20
Value
0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
--  GENERATESERIES works with date and time too, 
--  because dates are numbers.
EVALUATE 
    GENERATESERIES ( 
        DATE ( 2021, 1, 28 ),
        DATE ( 2021, 2, 3 ),
        1
    )
ORDER BY [Value]

EVALUATE
SELECTCOLUMNS (
    GENERATESERIES (
        TIME ( 0, 0, 0 ),
        TIME ( 23, 59, 59 ),
        TIME ( 2, 30, 0 )
    ),
    "Time", FORMAT ( [Value], "hh:mm:ss" )
)
Value
2021-01-28
2021-01-29
2021-01-30
2021-01-31
2021-02-01
2021-02-02
2021-02-03
Time
00:00:00
02:30:00
05:00:00
07:30:00
10:00:00
12:30:00
15:00:00
17:30:00
20:00:00
22:30:00

This example uses GENERATE to create a table for time within a day with the minute granularity.

EVALUATE
//Time Dimension 
//Working Hours 9:00am to 5:00pm 
VAR Opening = 9
VAR Closing = 17
//Time Slot 
VAR TimeSlot = 30
VAR Offset = ( TimeSlot / 2 )
RETURN
    GENERATE (
        GENERATESERIES ( 0, 1439, 1 ),
        // 24 hours/day * 60 minutes/hour = 1,440 - 1 (initial time 12am) 
        VAR __Minutes = [Value]
        VAR __Time =
            TIME ( 0, __Minutes, 0 )
        // MROUND: Rounds Value to the nearest multiple of TimeSlot
        VAR __MinutesRounded =
            MROUND ( ( __Minutes + Offset ), TimeSlot )
        VAR __StartTimeSlotRounded =
            TIME ( 0, __MinutesRounded - TimeSlot, 0 )
        VAR __EndTimeSlotRounded =
            TIME ( 0, __MinutesRounded, 0 )
        RETURN
            ROW (
                    "Hour", HOUR ( __Time ),
                    "Minute", MINUTE ( __Time ),
                    "Hour Minute 24h", FORMAT ( __Time, "hh:mm" ),
                    "Hour Minute 12h", FORMAT ( __Time, "hh:mm AM/PM" ),
                    "30 Minute Slot Start", FORMAT ( __StartTimeSlotRounded, "hh:mm" ),
                    "30 Minute Slot End", FORMAT ( __EndTimeSlotRounded, "hh:mm" ),
                    "30 Minute Slot", FORMAT ( __StartTimeSlotRounded, "hh:mm" ) & "-"
                        & FORMAT ( __EndTimeSlotRounded, "hh:mm" ),
                    "Working Hours", IF (
                        ( __Minutes / 60 ) >= Opening
                            && ( __Minutes / 60 ) <= Closing,
                        "Yes",
                        "No"
                    ),
                    "Time", __Time,
                    "TimeSlot Start", __StartTimeSlotRounded,
                    "TimeSlot End", __EndTimeSlotRounded
            )
    )
Value Hour Minute Hour Minute 24h Hour Minute 12h 30 Minute Slot Start 30 Minute Slot End 30 Minute Slot Working Hours Time TimeSlot Start TimeSlot End
0 0 0 00:00 12:00 AM 00:00 00:30 00:00-00:30 No 00:00:00 00:00:00 00:30:00
1 0 1 00:01 12:01 AM 00:00 00:30 00:00-00:30 No 00:01:00 00:00:00 00:30:00
2 0 2 00:02 12:02 AM 00:00 00:30 00:00-00:30 No 00:02:00 00:00:00 00:30:00
3 0 3 00:03 12:03 AM 00:00 00:30 00:00-00:30 No 00:03:00 00:00:00 00:30:00
4 0 4 00:04 12:04 AM 00:00 00:30 00:00-00:30 No 00:04:00 00:00:00 00:30:00
5 0 5 00:05 12:05 AM 00:00 00:30 00:00-00:30 No 00:05:00 00:00:00 00:30:00
6 0 6 00:06 12:06 AM 00:00 00:30 00:00-00:30 No 00:06:00 00:00:00 00:30:00
1,438 23 58 23:58 11:58 PM 23:30 00:00 23:30-00:00 No 23:58:00 23:30:00 00:00:00
1,439 23 59 23:59 11:59 PM 23:30 00:00 23:30-00:00 No 23:59:00 23:30:00 00:00:00

Related articles

Learn more about GENERATESERIES in the following articles:

Last update: Mar 13, 2024   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://docs.microsoft.com/en-us/dax/generateseries-function

2018-2024 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of GENERATESERIES? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.