Skip to main content

sublist

Returns a sublist of the input list, based on the given start and end indexes.

If the input list is (10, 2, 17, 23, 35) and the start index is 2, the function returns the sublist (17, 23, 35). This is because the function uses zero-based indexing. The start index is 2, so the first value in the sublist is the third number in the input list (17). No end index is set, so the function returns 17 and each subsequent number.

If you set the end index to 4, the function returns the sublist (17, 23). Again, zero-based indexing applies. The end index is 4, which represents the fifth number in the input list (35). The function excludes this fifth number from the sublist because the end index is exclusive.

Tip

You can also get a sublist by slicing. See ATL guide > Slicing for guidance.

Parameters

  • INPUT LIST (list, column, or row)

    The input list. This can be a list or list-like object (column or row).

  • START INDEX (number)

    The start index. The first value = index 0. The start index is inclusive. If you give a negative value, the function defines the start index by counting back from the end of the input list.

  • END INDEX (number)

    Optional. The end index. The end index is exclusive. If you give a negative value, the function defines the end index by counting back from the end of the input list.

    Default: All values from the start index onward are included.

Examples

Use the second parameter to define the start index (inclusive).

ATL in Script

Sublist

Printed Result

[[sublist((10, 2, 17, 23, 35), 2)]]

(17, 23, 35)

17, 23 and 35

[[sublist((10, 2, 17, 23, 35), 3)]]

(23, 35)

23 and 35

Use the third parameter to define the end index (exclusive).

ATL in Script

Sublist

Printed Result

[[sublist((10, 2, 17, 23, 35), 0, 3)]]

(10, 2, 17)

10, 2 and 17

[[sublist((10, 2, 17, 23, 35), 0, 4)]]

(10, 2, 17, 23)

10, 2, 17 and 23

When an index value is negative, the function counts backwards from the end of the list.

ATL in Script

Sublist

Printed Result

[[sublist((10, 2, 17, 23, 35), -3)]]

(17, 23, 35)

17, 23 and 35

[[sublist((10, 2, 17, 23, 35), 0, -1)]]

(10, 2, 17, 23)

10, 2, 17 and 23

If the end index value exceeds the number of values in the list, the function acts as though no end index is specified — in other words, it returns every value from the start index onward.

ATL in Script

Sublist

Printed Result

[[sublist((10, 2, 17, 23, 35), 2, 10)]]

(17, 23, 35)

17, 23 and 35

Using sublist with table data

Assume a "Describe the Table" project with this data:

ID

Branch

salesRev

COGS

otherRev

otherExp

netProfit

Row 1

01

Aberdeen

14,000

8,000

2,000

1,500

6,500

Row 2

02

Edinburgh

33,000

19,000

2,000

3,500

12,500

Row 3

03

Inverness

16,000

8,250

1,200

1,500

7,450

Row 4

04

Glasgow

32,500

17,750

1,250

1,700

14,300

Row 5

05

Dundee

15,750

7,500

1,250

1,200

8,300

Row 6

06

Perth

14,500

8,000

1,000

1,400

6,100

Here's how you might use sublist with other functions to produce narrative text:

[[

sortedData = sortByColumnNumbersReverse(WholeTable, 'netProfit')

branchesByProfit = columnsInRegion(sortedData, Branch)

topThreeList = sublist(branchesByProfit, 0, 3)

"The three most profitable branches are [[topThreeList]]."

]]

The output text:

The three most profitable branches are Glasgow, Edinburgh and Dundee.

Note

In a "Describe Row in Context" project, the column variable is BranchColumn.