Window functions to add formula columns

Window functions to add formula columns



A window function performs calculations across a group of rows in a table, called a window. You can use window functions to perform summations and calculations based on a rolling window of data, relative to the current row. Unlike a normal aggregate function, which returns a single output for the rows it is applied on, a window function retains every row in its result.

Zoho DataPrep provides 315 built-in functions in total. This page lists the 16 window functions. The remaining 299 functions are available in the Add formula transform - see Functions available to add formula columns.





Learn more about window functions with an example from this video.




List of window functions in DataPrep


Rolling Sum

rolling_sum(col1,rowsbefore,rowsafter)

Returns the rolling sum value from a window of rows, consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0
Example
Function
Sort rows by
Group rows by
rolling_sum('Sales', 1, 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Sum
21/02/2012
Groceries
120
220
12/05/2012
Groceries
100
330
15/06/2012
Groceries
110
210
22/01/2012
Stationery
200
300
10/04/2012
Stationery
100
300

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_sum(`col1`) is the same as rolling_sum(`col1`, -1, 0).



Rolling Average

rolling_avg(col1,rowsbefore,rowsafter)

Returns the rolling average value from a window of rows consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
rolling_avg(`Sales` , 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Avg
21/02/2012
Groceries
120
110
12/05/2012
Groceries
100
110
15/06/2012
Groceries
110
105
22/01/2012
Stationery
200
150
10/04/2012
Stationery
100
150

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_avg(`col1`) is the same as rolling_avg(`col1`, -1, 0).



Rolling Minimum

rolling_min(col1,rowsbefore,rowsafter)

Returns the rolling minimum value from a window of rows consisting of a number of rows before and after the current row

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
rolling_min(`Sales` , 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Min
21/02/2012
Groceries
120
100
12/05/2012
Groceries
100
100
15/06/2012
Groceries
110
100
22/01/2012
Stationery
200
100
10/04/2012
Stationery
100
100

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_min(`col1`) is the same as rolling_min(`col1`, -1, 0).



Rolling Maximum

rolling_max(col1,rowsbefore,rowsafter)

Returns the rolling maximum value from a window of rows consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
rolling_max(`Sales` , 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Max
21/02/2012
Groceries
120
120
12/05/2012
Groceries
100
120
15/06/2012
Groceries
110
110
22/01/2012
Stationery
200
200
10/04/2012
Stationery
100
200

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_max(`col1`) is the same as rolling_max(`col1`, -1, 0).



Rolling Standard Deviation

rolling_stddev(col1,rowsbefore,rowsafter)

Returns the rolling standard deviation value from a window of rows consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
rolling_stddev(`Sales` , 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Stddev
21/02/2012
Groceries
120
10
12/05/2012
Groceries
100
8.16496580927726
15/06/2012
Groceries
110
5
22/01/2012
Stationery
200
50
10/04/2012
Stationery
100
50

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_stddev(`col1`) is the same as rolling_stddev(`col1`, -1, 0).



Rolling Variance

rolling_variance(col1,rowsbefore,rowsafter)

Returns the rolling variance value from a window of rows consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
rolling_variance(`Sales` , 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Variance
21/02/2012
Groceries
120
100
12/05/2012
Groceries
100
66.66666666666667
15/06/2012
Groceries
110
25
22/01/2012
Stationery
200
2500
10/04/2012
Stationery
100
2500

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_variance(`col1`) is the same as rolling_variance(`col1`, -1, 0).



Rolling Count

rolling_count(col1,rowsbefore,rowsafter)

Returns the rolling count values (that are not null) from a window of rows consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
rolling_count(`Sales` , 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rolling Count
21/02/2012
Groceries
120
2
12/05/2012
Groceries
100
3
15/06/2012
Groceries
110
2
22/01/2012
Stationery
200
2
10/04/2012
Stationery
100
2

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: rolling_count(`col1`) is the same as rolling_count(`col1`, -1, 0).



Row Number

row_number()

Returns the row number from a window of rows based on the sort by and group by conditions.

Example
Function
Sort rows by
Group rows by
row_number()
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Row Number
21/02/2012
Groceries
120
1
12/05/2012
Groceries
100
2
15/06/2012
Groceries
110
3
22/01/2012
Stationery
200
1
10/04/2012
Stationery
100
2


Fill

fill(col1,fillEmpty,rowsbefore,rowsafter)

Returns the values from the column with empty cells filled by the closest non-empty value from the preceding rows within the window of rows consisting of a number of rows before and after the current row.

Parameters
Name
Description

col1

Decimal

Specifies the source column. This parameter is mandatory and must be a numeric value from a column or an expression that returns a number.

fillEmpty

Boolean

Specify true if the empty rows should be filled, false otherwise.

rowsbefore

Number

[Optional] Specifies the number of rows before the current row. The default value is -1 which includes all the rows before the current row.

rowsafter

Number

[Optional] Specifies the number of rows after the current row. The default value is 0 which includes the current row.
Example
Function
Sort rows by
Group rows by
fill(`Sales`, false, 1 , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Groceries

21/02/2012
Groceries

12/05/2012
Groceries
120
15/06/2012
Groceries
120
Output
Date
Product
Price
Fill
22/01/2012
Groceries


21/02/2012
Groceries

120
12/05/2012
Groceries
120
120
15/06/2012
Groceries
120
120
10/04/2012
Stationery
100
100

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: fill(`col1`, `fillEmpty`) is the same as fill(`col1`, `fillEmpty`, -1, 0).



Lag

lag(col1,rowsbefore)

Returns the value at a specified number of rows preceding the current row in the column.

Parameters
Name
Description

col1

Text

Specifies the source column. This parameter can be a column of any datatype.

rowsbefore

Number

Specifies the number of rows before the current row.
Example
Function
Sort rows by
Group rows by
lag(`Sales` , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Lag
21/02/2012
Groceries
120

12/05/2012
Groceries
100
120
15/06/2012
Groceries
110
100
22/01/2012
Stationery
200

10/04/2012
Stationery
100
200


Lead

lead(col1,rowsafter)

Returns the value at a specified number of rows after the current row in the column.

Parameters
Name
Description

col1

Text

Specifies the source column. It is mandatory and can be of a string type column.

rowsafter

Number

Specifies the number of rows after the current row.
Example
Function
Sort rows by
Group rows by
lead(`Sales` , 1)
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Lead
21/02/2012
Groceries
120
100
12/05/2012
Groceries
100
110
15/06/2012
Groceries
110

22/01/2012
Stationery
200
100
10/04/2012
Stationery
100



Rank

rank()

Returns the ranking from a window of rows based on the sort by and group by conditions. If there is a tie, the subsequent number of ranks are skipped in the following rows.

Example
Function
Sort rows by
Group rows by
rank()
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
10/05/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Rank
21/02/2012
Groceries
120
1
12/05/2012
Groceries
100
1
15/06/2012
Groceries
110
3
10/04/2012
Stationery
100
1
10/05/2012
Stationery
200
2


Dense Rank

dense_rank()

Returns the dense ranking from a window of rows based on the sort by and group by conditions. If there is a tie, there is no rank that is skipped.

Example
Function
Sort rows by
Group rows by
dense_rank()
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
10/05/2012
Stationery
200
20/02/2012
Groceries
120
21/02/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Dense Rank
20/02/2012
Groceries
120
1
21/02/2012
Groceries
100
1
15/06/2012
Groceries
110
2
10/04/2012
Stationery
100
1
10/05/2012
Stationery
200
2


Cumulative distribution

cumulative_distribution()

Returns the cumulative distribution values from a window of rows.

Example
Function
Sort rows by
Group rows by
cumulative_distribution()
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
cumulative Distribution
21/02/2012
Groceries
120
0.3333
12/05/2012
Groceries
100
0.6667
15/06/2012
Groceries
110
1
22/01/2012
Stationery
200
0.5
10/04/2012
Stationery
100
1


First Value

first(value,ignoreNulls,default)

Returns the first value of an expression for a group of rows. If isIgnoreNull is true, null values are skipped. A default value can be used when all values are null.

Parameters
Name
Description

value

Text

Specifies the source column from which the first value will be retrieved.

ignoreNulls

Number

Optional. Set to 1 to skip nulls and return the first non-null value. Default is 0.

default

Text

Optional. Specifies a default value to return if all values are null.
Example
Function
Sort rows by
Group rows by
first('Price')
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
NULL
21/02/2012
Groceries
NULL
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
First Value
10/04/2012
Stationery
100
100
22/01/2012
Stationery
NULL
100
21/02/2012
Groceries
NULL
100
12/05/2012
Groceries
100
100
15/06/2012
Groceries
110
100

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: first(`value`) is the same as first(`value`, 0, '').



Last Value

last(value,ignoreNulls,default)

Returns the last value of an expression for a group of rows. If ignoreNulls is set to 1, null values are skipped. A default value can be used when all values are null.

Parameters
Name
Description

value

Text

Specifies the source column from which the last value will be retrieved.

ignoreNulls

Number

Optional. Set to 1 to skip nulls and return the last non-null value. Default is 0.

default

Text

Optional. Specifies a default value to return if all rows are null.
Example
Function
Sort rows by
Group rows by
last('Price')
Date
Product
Input
Date
Product
Price
10/04/2012
Stationery
100
22/01/2012
Stationery
200
21/02/2012
Groceries
120
12/05/2012
Groceries
100
15/06/2012
Groceries
110
Output
Date
Product
Price
Last Value
21/02/2012
Groceries
120
110
15/06/2012
Groceries
110
110
12/05/2012
Groceries
100
110
22/01/2012
Stationery
200
100
10/04/2012
Stationery
100
100

Note: Optional parameters can be skipped and the default values will be auto-applied. For example: last(`value`) is the same as last(`value`, 0, '').




ntile


Syntax
ntile(n)

Divides the rows in each window partition into n ordered buckets and returns the bucket number for each row.

Parameters
NameDescription

n

Number

Specifies the number of ordered buckets to divide the rows into.
Example
FunctionSort rows byGroup rows by
ntile(2)DateProduct
Input
DateProductPrice
10/04/2012Stationery100
22/01/2012Stationery200
21/02/2012Groceries120
12/05/2012Groceries100
15/06/2012Groceries110
Output
DateProductPriceNtile
21/02/2012Groceries1201
12/05/2012Groceries1001
15/06/2012Groceries1102
22/01/2012Stationery2001
10/04/2012Stationery1002
See also

        Create. Review. Publish.

        Write, edit, collaborate on, and publish documents to different content management platforms.

        Get Started Now


          Access your files securely from anywhere

            Zoho CRM Training Programs

            Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

            Zoho CRM Training
              Redefine the way you work
              with Zoho Workplace

                Zoho DataPrep Personalized Demo

                If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

                Zoho CRM Training

                  Create, share, and deliver

                  beautiful slides from anywhere.

                  Get Started Now


                    Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                    BOOK A SESSION







                                Quick LinksWorkflow AutomationData Collection
                                Web FormsEnterpriseOnline Data Collection Tool
                                Embeddable FormsBankingBegin Data Collection
                                Interactive FormsWorkplaceData Collection App
                                CRM FormsCustomer ServiceAccessible Forms
                                Digital FormsMarketingForms for Small Business
                                HTML FormsEducationForms for Enterprise
                                Contact FormsE-commerceForms for any business
                                Lead Generation FormsHealthcareForms for Startups
                                Wordpress FormsCustomer onboardingForms for Small Business
                                No Code FormsConstructionRSVP tool for holidays
                                Free FormsTravelFeatures for Order Forms
                                Prefill FormsNon-Profit

                                Intake FormsLegal
                                Mobile App
                                Form DesignerHR
                                Mobile Forms
                                Card FormsFoodOffline Forms
                                Assign FormsPhotographyMobile Forms Features
                                Translate FormsReal EstateKiosk in Mobile Forms
                                Electronic Forms
                                Drag & drop form builder

                                Notification Emails for FormsAlternativesSecurity & Compliance
                                Holiday FormsGoogle Forms alternative GDPR
                                Form to PDFJotform alternativeHIPAA Forms
                                Email FormsFormstack alternativeEncrypted Forms

                                Wufoo alternativeSecure Forms

                                TypeformWCAG

                                  Zoho FSM Video Tutorials


                                        All-in-one knowledge management and training platform for your employees and customers.

                                                  Create. Review. Publish.

                                                  Write, edit, collaborate on, and publish documents to different content management platforms.

                                                  Get Started Now




                                                                    You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                        Manage your brands on social media


                                                                          • Desk Community Learning Series


                                                                          • Digest


                                                                          • Functions


                                                                          • Meetups


                                                                          • Kbase


                                                                          • Resources


                                                                          • Glossary


                                                                          • Desk Marketplace


                                                                          • MVP Corner


                                                                          • Word of the Day


                                                                          • Ask the Experts


                                                                            Zoho Sheet Resources

                                                                             

                                                                                Zoho Forms Resources


                                                                                  Secure your business
                                                                                  communication with Zoho Mail


                                                                                  Mail on the move with
                                                                                  Zoho Mail mobile application

                                                                                    Stay on top of your schedule
                                                                                    at all times


                                                                                    Carry your calendar with you
                                                                                    Anytime, anywhere




                                                                                          Zoho Sign Resources

                                                                                            Sign, Paperless!

                                                                                            Sign and send business documents on the go!

                                                                                            Get Started Now




                                                                                                    Zoho TeamInbox Resources





                                                                                                              Zoho DataPrep Demo

                                                                                                              Get a personalized demo or POC

                                                                                                              REGISTER NOW


                                                                                                                Design. Discuss. Deliver.

                                                                                                                Create visually engaging stories with Zoho Show.

                                                                                                                Get Started Now








                                                                                                                                    • Related Articles

                                                                                                                                    • Window functions to add formula columns

                                                                                                                                      A window function is used to perform calculations across a group of rows on a dataset. A set of rows is termed a window. You can use window functions to perform summations and calculations based on a rolling window of data, relative to the current ...
                                                                                                                                    • Functions available to add formula columns

                                                                                                                                      Zoho DataPrep provides 361 built-in functions to transform, calculate, and derive new values from your data. Of these, 344 functions can be used with the Add formula transform to create formula columns, and the remaining 17 are window functions. This ...
                                                                                                                                    • Add formula

                                                                                                                                      You can create new columns and customize them using the Formula column transform. Zoho DataPrep offers a variety of functions to suit your needs. Click here to know more about the functions. To create a formula column 1. Click on the Transform menu ...
                                                                                                                                    • Fill empty cells

                                                                                                                                      DataPrep allows you to fill the empty cells in a column using the Fill empty cells transform. To fill empty cells 1. Right-click the column name and select the Fill empty cells option from the context menu. 2. Choose one of the following options from ...
                                                                                                                                    • Add prefix or suffix

                                                                                                                                      DataPrep allows you to add prefixes and suffixes to your data. To add a prefix or a suffix to a column 1. Right-click on a column and select the Add Prefix or Suffix option from the context menu. 2. Enter the prefix, suffix, or both in the text ...
                                                                                                                                      Wherever you are is as good as
                                                                                                                                      your workplace

                                                                                                                                        Resources

                                                                                                                                        Videos

                                                                                                                                        Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                        eBooks

                                                                                                                                        Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                        Webinars

                                                                                                                                        Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                        CRM Tips

                                                                                                                                        Make the most of Zoho CRM with these useful tips.



                                                                                                                                          Zoho Show Resources