# Using the Shared Dimension step for SDR

The Shared Dimension step works in much the same way as the [Annotate Stream](https://docs.pentaho.com/pdia-data-integration/extracting-data-into-pdi/work-with-the-streamlined-data-refinery/use-the-streamlined-data-refinery/building-blocks-for-the-sdr/using-the-annotate-stream-step) step, refining your data through the creation of dimensions that can be shared for later use. You must designate one annotation in the Shared Dimension step as the dimension key.

You can create multiple annotations on the same field, such as an attribute and a dimension key. For example, in the Shared Dimension step, you can select the field **Year** and annotate it as a dimension key. You can also select the field **Year** again to annotate it as an attribute. You can also create multiple annotations to modify the same data model.

The transformation that builds a shared dimension should run before the [Build Model job entry](https://docs.pentaho.com/pdia-data-integration/extracting-data-into-pdi/work-with-the-streamlined-data-refinery/use-the-streamlined-data-refinery/building-blocks-for-the-sdr/use-the-build-model-job-entry-for-sdr), or in a separate job that runs before Build Model. Here is an example transformation for a shared dimension.

![Shared dimension workflow](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-979bb0bedea71f12aaef7717667b0e3c81ab20ee%2FSDR_SharedDimensionWorkflow.png?alt=media)

After you are done with your data model, you are ready to [publish](https://docs.pentaho.com/pdia-data-integration/extracting-data-into-pdi/work-with-the-streamlined-data-refinery/use-the-streamlined-data-refinery/building-blocks-for-the-sdr/using-the-publish-model-job-entry-for-sdr) it.

## Metadata injection support

All fields of this step support metadata injection. You can use it with [ETL metadata injection](https://docs.pentaho.com/pdia-data-integration/pdi-transformation-steps-reference-overview/etl-metadata-injection) to pass metadata to your transformation at runtime.

When using metadata injection with the Shared Dimension step, the system loads the currently defined annotations in the Shared Dimension step, whether or not the shared dimension name is a match. The new set of annotations is saved to the transformation and in the metastore. If a shared dimension with the same name already exists in the metastore, it is overwritten with the new shared dimension.

## Create a shared dimension

This section describes how to create a shared dimension.

**Note:** Be sure to create one annotation to serve as the dimension key.

1. In the **Design** tab, click the **Flow** folder, and then double-click the **Shared Dimension** step icon. Alternatively, you can drag the step icon on to the transformation canvas.

   ![Shared Dimension step icon](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-76752a8078db36e65d6947af57833a49b8bda80d%2FSDR_SharedDimension_Icon.png?alt=media)
2. Double-click the **Shared Dimension** icon to open the Shared Dimension dialog box.
3. Enter a name for the step in the **Step name** field.
4. If you are basing your new dimension on an existing shared dimension, select it from the **Shared Dimension Name** drop-down list of available shared dimensions, or enter a new name for it.
5. Select a source to associate your dimension from the **Data Provider Step** drop-down list.

   The following steps are valid sources:

   * Combination Lookup
   * Database Lookup
   * Dimension Lookup
   * Insert/Update
   * Table Output
   * Vertica Bulk Loader
6. Enter a description of the shared dimension in the **Description** field.
7. Select available fields for annotation.
   1. Click the **Select Fields** button to open the Select Fields to Annotate dialog box.
   2. Double-click the fields in the **Available Fields** list to add them to the**Selected Fields** list.

      For example, you might select **Year** to annotate as your dimension key and **Year**, **Month**, and **Week** to annotate as attributes Optionally, you can use the arrows to move one or more fields to the **Selected Fields** list.
   3. When finished, click **OK** to close the dialog box. The selected fields now display in the **Annotations** table featuring the following columns:

| Column           | Description                                                                                                                                                                                                                                                                                            |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Field**        | Lists the names of the fields selected for annotation.                                                                                                                                                                                                                                                 |
| **Model Action** | <p>Specifies which model action is being taken:- <a href="using-the-annotate-stream-step/creating-attributes">Creating attributes</a></p><ul><li><a href="broken-reference">Create a dimension key</a>: the selected field will be designated as the dimension key for the shared dimension.</li></ul> |
| **Summary**      | Displays a summary of that specific annotation.                                                                                                                                                                                                                                                        |

8\. Now you can create \[annotations]\(../Using%20the%20Annotate%20Stream%20step.md) for the selected fields.

```
1.  To annotate a field, double-click it in the **Annotations** section. Optionally, you can select the select the field in the **Annotations** table and then select the **Edit** \(Pencil icon\) in the upper-right corner.

    The Annotate dialog box appears for the selected field.

2.  In the **Actions** field, click the drop-down arrow to select one of the following actions:

    -   **Create Attribute**. See [Creating attributes](../Using%20the%20Annotate%20Stream%20step/Use%20the%20Annotate%20Stream%20step/Creating%20attributes.md).
    -   **Create Dimension Key**. See [Create a dimension key](../Using%20the%20Annotate%20Stream%20step/Use%20the%20Annotate%20Stream%20step/Creating%20Link%20Dimensions%20for%20SDR/Create%20a%20dimension%20key.md).
3.  You can use the **Previous** and **Next** buttons to navigate through the fields. When finished, click **OK** to continue or **Cancel** to close the dialog box without saving your annotations.

    **Note:** You can remove a field from the **Annotations** section by selecting it in the table and then clicking the **Delete** \(X icon\) in the upper-right corner.
```

9\. Click **Apply** to save changes you made to an annotation. Click **OK** to continue or **Cancel** to close the dialog box.

This is an example of the Shared Dimensions dialog box.

![Shared Dimension step](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-3408aca048ce6e8e6c07a57b36be77c556f7f66e%2FSDR_SharedDimension_db.png?alt=media)

## Create a dimension key in Shared Dimension step

To use a shared dimension, you will need to designate one annotation in the Shared Dimension step as the dimension key. Since you can create multiple annotations on the same field, you can use a selected field as an annotation and as the dimension key. For example, you might want to create an attribute and a dimension key on the field Year in your time dimension.

1. If you have not done so already, complete steps 1-8 of [Create a shared dimension](https://docs.pentaho.com/pdia-data-integration/extracting-data-into-pdi/work-with-the-streamlined-data-refinery/use-the-streamlined-data-refinery/building-blocks-for-the-sdr/broken-reference).
2. Select **Create Dimension Key** from the **Actions** menu.

   The **Name - Value** table auto-populates with the **Dimension** attribute.

   ![Create dimension key](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-89ede2e77c83caa95decc395941feeca1e59463b%2FSDR_CreateDimensionKey.png?alt=media)
3. Enter or select a dimension in the **Value** field for **Dimension**. The selected field will be used as the key for this dimension.
4. Click **OK** to finish or click **Cancel** to exit.

   In the Shared Dimension dialog box, the selected field will now appear with the summary that it is the key for the shared dimension. For example, the field `'Calendar Year'` may display `'Calendar Year is key for dimension Year'` in the **Summary** column.

   ![Shared Dimension with Calendar Year](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-3408aca048ce6e8e6c07a57b36be77c556f7f66e%2FSDR_SharedDimension_db.png?alt=media)

You can use a single field more than once, so you will be able to use the field you selected here for both the key and to create annotations.
