> ## Documentation Index
> Fetch the complete documentation index at: https://www.integrate.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ETL: Window Transformation

> Use the Window transformation to apply SQL-style window functions like ranking, moving averages, and running totals to your ETL pipeline data.

<Frame>
  <img src="https://mintcdn.com/integrateio/HSGmKiO3soPLENmi/images/creating-packages/using-components-window-transformation/image-1.png?fit=max&auto=format&n=HSGmKiO3soPLENmi&q=85&s=397c29d47bed8b28c45c1ffd5cbefd53" alt="Window component configuration with partitioning and sort options" width="1200" height="828" data-path="images/creating-packages/using-components-window-transformation/image-1.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/integrateio/HSGmKiO3soPLENmi/images/creating-packages/using-components-window-transformation/image-2.png?fit=max&auto=format&n=HSGmKiO3soPLENmi&q=85&s=633dbdc1e57a234f80ca90a002ab87e0" alt="Window function selection with field and alias settings" width="1200" height="828" data-path="images/creating-packages/using-components-window-transformation/image-2.png" />
</Frame>

## Data partitioning

Select `Treat entire input as a single partition` to treat the entire dataset as a single window or `Partition input data by fields` to determine the partitioning of the incoming dataset to windows. Each partition contains of all the records that have the same values in the partitioning fields.

<Steps>
  <Step>
    Select a field in the dropdown list.
  </Step>

  <Step>
    Click the **+** button to add another partitioning field.
  </Step>

  <Step>
    Click the **X** button to remove a field from the **partition by** list.
  </Step>
</Steps>

## Data order

Select `Don’t sort input data` if you do not want to sort input data, or `Sort partition by fields` to add fields that determine the sorting of the data within a window. Sorting is optional but recommended for many windowing functions, since order-dependent results like "first" or "last" require a defined sort order.

<Steps>
  <Step>
    Select a field in the dropdown list.
  </Step>

  <Step>
    Specify sort order - ascending or descending.
  </Step>

  <Step>
    Click the **+** button to add another sorting field.
  </Step>

  <Step>
    Click the **X** button to remove a field from the **sort by** list.
  </Step>
</Steps>

<Note>
  When you select `Treat entire input as a single partition` and `Don’t sort input data`, the Window component preserves input row order in its output. Order-sensitive functions such as **Lead**, **Lag**, **First Value**, **Last Value**, and **Row number** evaluate against the original input order, and the records leave the component in that same order. If you need a different order, use `Sort partition by fields` to set it explicitly.

  For partitioned windows (`Partition input data by fields`) without an explicit sort, record order within a partition remains undefined. Add `Sort partition by fields` when an order-sensitive function depends on it.
</Note>

## Window functions

Select the functions to apply to the window and fill in their arguments.

<Steps>
  <Step>
    Select **function** from the dropdown (see list below).
  </Step>

  <Step>
    Fill in the field and arguments.
  </Step>

  <Step>
    Type an alias for the field containing the resulting value.
  </Step>

  <Step>
    Click the **+** button to add another function.
  </Step>

  <Step>
    Click the **X** button to remove a function.
  </Step>
</Steps>

## Functions list

* **Count** - returns the number of non-null values in a field within a window range (see range arguments below).
* **Sum** - returns the sum of values in a numeric field within a window range. For example, use frame between -∞ and 0 for a running total.
* **Average** - returns the average of values in a numeric field within a window range. For example, use frame between -2 and 2 for a moving average on 5 values.
* **Min** - returns the minimum value in a field within a window range.
* **Max** - returns the maximum value in a field within a window range.
* **First Value** - returns the first value in a field within a window range. Make sure the window is sorted.
* **Last Value** - returns the last value in a field within a window range. Make sure the window is sorted.
* **Lead** - returns the value from a field in a subsequent record within the window range. The location of the subsequent record (relative to the current record) is defined by the **offset** argument. The **default** argument is returned if the lead record can't be found (for example, when the current record is at the end of the window range). Example: use offset of 1 to get the value from a field in the next record.
* **Lag** - returns the value from a field in a preceding record within the window range. The location of the preceding record (relative to the current record) is defined by the **offset** argument. The **default** argument is returned if the lag record can't be found (for example, when the current record is at the beginning of the window range). Example: use offset of 1 to get the value from a field in the previous record.
* **Row number** - returns a sequential number for each record within a window range according to the window's ordering.
* **NTILE** - distributes the records within a window range into a specified number of buckets set by the argument **number of ntiles**. For example, use NTILE on data partitioned by class and sorted by grades to divide each class into 4 groups of students according to their grades.

### Range arguments

Per function, the range arguments further limit the records within the window. The range is relative to the current record and is defined by the number of records preceding the current record and the number of records following the current record. The default values are -∞ ("unbounded preceding" in SQL terminology) and +∞ ("unbounded following"). 0 stands for the current record.

Other examples:

* "-2" in **range before** means 2 records preceding the current record are the lower boundary for the function.
* "5" in **range after** means 5 records after the current record are the upper boundary for
