Skip to main content

If FIRST(column) would return the first element and LAST(column) the last one, I would like to obtain the n-th element of that list. There isn't a straightforward function to do that but is there a way?

Hi,

 

Just use INDEX_ORDER() function. Sort by specific column, and then just filter it by INDEX_ORDER value.

F.e. if you want to add values only form the 3rd element and 5th element of the list use:

SUM(CASE WHEN INDEX_ORDER (TABLE.COLUMN, ORDER BY(TABLE.COLUMN ASC) = 3 OR INDEX_ORDER (TABLE.COLUMN, ORDER BY (TABLE>COLUMN ASC)) = 5 THEN TABLE>COLUMN ELSE 0 END)

 

Let us know if that's the thing you needed - if actually helped, mark as best answer.

 

Best Regards,

Mateusz Dudek


Reply