Intro
Note: This article is for the old Magic ETL. For information on the new Magic ETL, see New Magic ETL.
Understanding Partitions
All functions also allow you to optionally specify a column to use as a partition. For example, if you had a series column called “State,” selecting “State” as the partition would cause the values in your new column to be divided by state. This is shown in the following example, wherein values in the “Amount” column are ranked in descending order and partitioned by state:
Ranking Functions
Ranking functions derive a ranking number for each value in a selected column and display it in a new column. There are three available ranking functions: Rank, Dense Rank, and Row Number.Rank
The Rank function assigns a rank number to each value in the selected column. If any cells in the column contain the same value, those cells are given the same ranking number, and a “gap” appears in the numbering depending on how many numbers were skipped. For example, if the first three cells in the column had a value of 100 and the next cell had a value of 200 and the values were set to be in ascending order, the first three cells would be ranked “1” and the fourth cell would be ranked “4.” The following screenshot shows an example of this:
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the ranking results (such as “Rank”).
- In the Select function type menu, select Rank.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want to rank. (A value column is recommended.)
- In Step 3 of the dialog, select the order you want the values in the column to be ranked in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Dense Rank
The Dense Rank function is the same as the Rank function, with one important difference. If any cells in the column contain the same value, those cells are given the same ranking number, as in a “Rank” function; however, the numbering continues as normal to the next cell (i.e. no “gap” appears). For example, if the first three cells in the column had a value of 100 and the next cell had a value of 200 and the values were set to be in ascending order, the first three cells would be ranked “1” and the fourth cell would be ranked “2.” The following screenshot shows an example of this:
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the ranking results (such as “Rank”).
- In the Select function type menu, select Dense Rank.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want to rank. (A value column is recommended.)
- In Step 3 of the dialog, select the order you want the values in the column to be ranked in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Row Number
The Row Number function returns the row numbers of all values in the selected column. Note that when partitioning is used, rows take the number of their row within the partition group, not necessarily the row number of the DataSet. This is shown in the following screenshot, in which the row numbering derived from the Row Number function restarts with each new partition. Thus, beginning with row 4, the derived row numbers are not the same as the DataSet row numbers.
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the ranking results (such as “Row Number”).
- In the Select function type menu, select Row Number.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want to derive row numbers for.
- In Step 3 of the dialog, select the order you want the values in the column to be sorted in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Framed Functions
Framed functions take a mathematical function and apply it to a cell in a column, along with a specified number of cells before it (“Preceding”) and after it (“Following”). The derived values appear in a new column. The following simple example shows how this works. For this example, the user has selected the Sum function and has indicated a Preceding value of 1 and a Following value of 2.

Average
The Average function takes the average of a given cell and its indicated Preceding and Following values. In the following example, the user has applied the Average function to the “Amount” column, set Preceding and Following values of 2, and set the “Cust” column as a partition.
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the derived values. It is suggested you pick a name indicating the number of Preceding and Following values, such as “Average (2P and 2F).”
- In the Select function type menu, select Average. Two new menus appear after you select your function type.
- In the Select column menu, select the column with values that will be averaged.
- In the Preceding and Following fields, enter the number of Preceding and Following values you want to include in your averages.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want your order to be based on.
- In Step 3 of the dialog, select the order you want the values in the new column to be sorted in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Count
The Count function returns a count of a given cell and its indicated Preceding and Following values. In the following example, the user has applied the Count function to the “Amount” column, set Preceding and Following values of 2, and set the “Cust” column as a partition.
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the derived values. It is suggested you pick a name indicating the number of Preceding and Following values, such as “Count (2P and 2F).”
- In the Select function type menu, select Count. Two new menus appear after you select your function type.
- In the Select column menu, select the column with values that will be counted.
- In the Preceding and Following fields, enter the number of Preceding and Following values you want to include in your counts.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want your order to be based on.
- In Step 3 of the dialog, select the order you want the values in the new column to be sorted in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Sum
The Sum function returns a sum of a given cell with its indicated Preceding and Following values. In the following example, the user has applied the Sum function to the “Amount” column, set Preceding and Following values of 2, and set the “Cust” column as a partition.
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the derived values. It is suggested you pick a name indicating the number of Preceding and Following values, such as “Sum (2P and 2F).”
- In the Select function type menu, select Sum. Two new menus appear after you select your function type.
- In the Select column menu, select the column with values that will be summed.
- In the Preceding and Following fields, enter the number of Preceding and Following values you want to include in your totals.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want your order to be based on.
- In Step 3 of the dialog, select the order you want the values in the new column to be sorted in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Offset Functions
Offset functions add a new column to your DataSet in which values are the same as those in a selected column but offset by a specified number of rows. Offset functions come in two types: the Lag function, in which the values in the new column are offset after the values in the original column, and the Lead function, in which the values in the new column are offset before the values in the original column. In both Lag and Lead functions, partitions are honored.Lag
In a Lag function, the values in your new column follow the values in your original column after a specified offset. In the following example, a Lag of 3 has been applied, and the “Cust” column has been added as a partition.
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the derived values. It is suggested you pick a name indicating the offset value of the lag.
- In the Select function type menu, select Lag. Two new menus appear after you select your function type.
- In the Select column menu, select the column with values that will appear in the new column.
- In the What rows should be included field, enter the desired offset value.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want your order to be based on.
- In Step 3 of the dialog, select the order you want the values in the new column to be sorted in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)
Lead
In a Lead function, the values in your new column precede the values in your original column after a specified offset. In the following example, a Lead of 3 has been applied, and the “Cust” column has been added as a partition.
- Click the Rank & Window action in the canvas.
-
(Optional) Rename the action by clicking
, then entering the name you want.
- Click Add Function.
- Add a name for the new column that will contain the derived values. It is suggested you pick a name indicating the offset value of the lead.
- In the Select function type menu, select Lead. Two new menus appear after you select your function type.
- In the Select column menu, select the column with values that will appear in the new column.
- In the What rows should be included field, enter the desired offset value.
- Click the Apply button in the top right corner of the dialog. Three new steps appear.
- In Step 2 of the dialog, select the column you want your order to be based on.
- In Step 3 of the dialog, select the order you want the values in the new column to be sorted in.
- (Optional) In Step 4 of the dialog, select the column to use as a partition, if any. (For an explanation of partitioning, see Understanding partitions at the top of this page.)