--- title: "CopyDiscreteIndex" slug: "copydiscreteindex" updated: 2022-02-10T17:44:44Z published: 2022-02-10T17:44:44Z canonical: "docs.datajet.app/copydiscreteindex" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # CopyDiscreteIndex ## General: CopyDiscreteIndex ## Returns a copy of the source discrete index, filtered by the optional dataset. Creates an Integer field with values 1 to N, where N is the number of discrete values in the source field. ## Purpose Use this function to: - Convert a field into an integer for use in calculations - To reveal the underlying index scope of a field ## Return Value | Property | Value | | --- | --- | | **FieldType** | Integer / LongInteger | | **FieldSize** | Low / Med / High | | **DataType** | Discrete | | **DataSize** | Byte / Short / Integer | ```shell Example Return Value: 1, 2, .... 123654 ``` ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/Gen_CopyDiscIndex_Sample.PNG) ## Parameters | Parameter | JSON | Description | | --- | --- | --- | | **Table** | “targetTable”: “MyTableName” | The target table on which the new field will be created | | **Filter** | “dataset”: {DataSet_JSON} | Optional. If a filter is applied, records not in the filter recordset will be returned as null. Use a filter to exclude records from the source field. If the source field has too many discrete values to create a DiscreteIndex, excluding some records may reduce the index size enough for a discrete index to be created.To specify records to exclude: 1. Select the records to be excluded and drag them into the HotBar 2. Right-click and choose the Invert function 3. Add the resulting Recordset as a filter | | **Function** | "function":"copydiscreteindex" | CopyDiscreteIndex | | **Source Field** | “p1”: “SourceFieldName” | Required. The Discrete (i.e., non-continuous) field from which to create the index. If it is necessary to create an index from a continuous field, depending on the field contents, the CONCAT function can sometimes be used to create a discrete copy of the continuous field. If the continuous field is a numeric field, the output from the CONCAT function can be cast back into a numeric field using the WILDICAST function. Strings can be cast as date fields using the DateFromString function. | ## JSON Sample ```json { "method": "BuildBakedField", "project": "D3", "targetTable": "transactions", "overwrite": true, "name": "date-index", "function": "copydiscreteindex", "p1": "date" } ``` ## Usage Notes The function only works on Discrete source fields. See CONCAT, WILDICAST and DATEFROMSTRING if it is necessary to create copies of Continuous fields. If a filter is applied, records which are not in the filter will be stored as NULL in copy. Applying a filter may reduce the number of discrete values sufficiently to create a discrete index. The maximum number of discrete values in a discrete index is 1,000,000 For more information on field and data types, see **Field Types and Data Types** See Also: - Engineering | Expression Field - CONCAT   (String Function) - WILDICAST (String Function) - DATEFROMSTRING   (String Function) ## Example | Example | Details | | --- | --- | | **Description** | Create a numeric index from average spend field | | **Input** | - Table: = [customer] - Filter: = [No Filter] - **Function: = CopyDiscreteIndex** - Source Field:= avgl_spend - Name: = spend_index | | **Sample** | ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/Gen_CopyDiscIndex_Example.png) |