

# Working with autonarrative computations
<a name="auto-narrative-computations"></a>

Use this section to help you understand what functions are available to you when you are customizing an autonarrative. You only need to customize a narrative if you want to change or build on the default computation.

After you create an autonarrative, the expression editor opens. You can also activate the expression editor by choosing the on-visual menu, and then **Customize Narrative**. To add a computation while using the expression editor, choose **\$1 Add computation**.

You can use the following code expression to build your autonarrative. These are available from the list that's labeled **Insert code**. Code statements can display inline (in a sentence) or as a block (in a list).
+ Expression – Create your own code expression.
+ IF – An IF statement that includes an expression after evaluating a condition. 
+ FOR – A FOR statement that loops through values. 

You can use the following computations to build your autonarrative. You can use the expression editor without editing any syntax, but you can also customize it if you want to. To interact with the syntax, open the computational widget in the autonarrative expression editor.

**Topics**
+ [

# ML-powered anomaly detection for outliers
](anomaly-detection-function.md)
+ [

# Bottom movers computation
](bottom-movers-function.md)
+ [

# Bottom ranked computation
](bottom-ranked-function.md)
+ [

# ML-powered forecasting
](forecast-function.md)
+ [

# Growth rate computation
](growth-rate-function.md)
+ [

# Maximum computation
](maximum-function.md)
+ [

# Metric comparison computation
](metric-comparison-function.md)
+ [

# Minimum computation
](minimum-function.md)
+ [

# Period over period computation
](period-over-period-function.md)
+ [

# Period to date computation
](period-to-date-function.md)
+ [

# Top movers computation
](top-movers-function.md)
+ [

# Top ranked computation
](top-ranked-function.md)
+ [

# Total aggregation computation
](total-aggregation-function.md)
+ [

# Unique values computation
](unique-values-function.md)

# ML-powered anomaly detection for outliers
<a name="anomaly-detection-function"></a>

The ML-powered anomaly detection computation searches your data for outliers. For example, you can detect the top three outliers for total sales on January 3, 2019. If you enable contribution analysis, you can also detect the key drivers for each outlier. 

To use this function, you need at least one dimension in the **Time** field well, at least one measure in the **Values** field well, and at least one dimension in the **Categories** field well. The configuration screen provides an option to analyze the contribution of other fields as key drivers, even if those fields aren't in the field wells.

For more information, see [Detecting outliers with ML-powered anomaly detection](anomaly-detection.md).

**Note**  
You can't add ML-powered anomaly detection to another computation, and you can't add another computation to an anomaly detection.

## Computation outputs
<a name="anomaly-detection-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name that you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. You can use items displayed in **`bold monospace font`** following in the narrative. 
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `categoryFields` – From the **Categories** field well.
  + `name` – The formatted display name of the field.
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `itemsCount` – The number of items included in this computation.
+ `items` – Anomalous items.
  + `timeValue` – The values in the date dimension.
    + `value` – The date/time field at the point of the anomaly (outlier).
    + `formattedValue` – The formatted value in the date/time field at the point of the anomaly.
  + `categoryName` – The actual name of the category (cat1, cat2, and so on).
  + `direction` – The direction on the x-axis or y-axis that's identified as anomalous: `HIGH` or `LOW`. `HIGH` means "higher than expected." `LOW` means "lower than expected." 

    When iterating on items, `AnomalyDetection.items[index].direction` can contain either `HIGH` or `LOW`. For example, `AnomalyDetection.items[index].direction='HIGH'` or `AnomalyDetection.items[index].direction=LOW`. `AnomalyDetection.direction` can have an empty string for `ALL`. An example is `AnomalyDetection.direction=''`. 
  + `actualValue` – The metric's actual value at the point of the anomaly or outlier.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field.
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
  + `expectedValue` – The metric's expected value at the point of the anomaly (outlier).
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field.
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.

# Bottom movers computation
<a name="bottom-movers-function"></a>

The bottom movers computation counts the requested number of categories by date that rank in the bottom of the autonarrative's dataset. For example, you can create a computation to find the bottom three products sold, by sales revenue.

To use this function, at least one dimension in the **Time** field well and at least one dimension in the **Categories** field well. 

## Parameters
<a name="bottom-movers-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank.

*Category*   
The category dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

*Number of movers*   
The number of ranked results that you want to display.

*Order by*   
The order that you want to use, percent difference or absolute difference.

## Computation outputs
<a name="bottom-movers-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 

**Note**  
These are the same output parameters as the ones that are returned by the top movers computation.
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `categoryField` – From the **Categories** field well.
  + `name` – The formatted display name of the field.
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `startTimeValue` – The value in the date dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `endTimeValue` – The value in the date dimension.
  + `value` – The raw value.
  + `formattedValue` – The absolute value formatted by the datetime field.
+ `itemsCount` – The number of items included in this computation.
+ `items`: Bottom moving items.
  + `categoryField` – The category field.
    + `value` – The value (contents) of the category field.
    + `formattedValue` – The formatted value (contents) of the category field. If the field is null, this displays '`NULL`'. If the field is empty, it displays '`(empty)`'.
  + `currentMetricValue` – The current value for the metric field.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
  + `previousMetricValue` – The previous value for the metric field.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
  + `percentDifference` – The percent difference between the current and previous values of the metric field.
    + `value` – The raw value of the calculation of the percent difference.
    + `formattedValue` – The formatted value of the percent difference (for example, -42%).
    + `formattedAbsoluteValue` – The formatted absolute value of the percent difference (for example, 42%).
  + `absoluteDifference` – The absolute difference between the current and previous values of the metric field.
    + `value` – The raw value of the calculation of the absolute difference.
    + `formattedValue` – The absolute difference formatted by the settings in the metric field's format preferences.
    + `formattedAbsoluteValue` – The absolute value of the difference formatted by the metric field.

# Bottom ranked computation
<a name="bottom-ranked-function"></a>

The bottom ranked computation calculates the requested number of categories by value that rank in the bottom of the autonarrative's dataset. For example, you can create a computation to find the bottom three states by sales revenue.

To use this function, you need at least one dimension in the **Categories** field well. 

## Parameters
<a name="bottom-ranked-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Category*   
The category dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

*Number of results*   
The number of ranked results that you want to display.

## Computation outputs
<a name="bottom-ranked-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 

**Note**  
These are the same output parameters as the ones that are returned by the top ranked computation.
+ `categoryField` – From the **Categories** field well.
  + `name` – The formatted display name of the field.
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `itemsCount` – The number of items included in this computation.
+ `items`: Bottom ranked items.
  + `categoryField` – The category field.
    + `value` – The value (contents) of the category field.
    + `formattedValue` – The formatted value (contents) of the category field. If the field is null, this displays '`NULL`'. If the field is empty, it displays '`(empty)`'.
  + `metricValue` – The metric field.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field.
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.

## Example
<a name="bottom-ranked-function-example"></a>

The following screenshot shows the default configuration for the bottom-ranked computation.

![\[Default configuration for the bottom-ranked computation.\]](http://docs.amazonaws.cn/en_us/quick/latest/userguide/images/bottom-ranked-computation.png)


# ML-powered forecasting
<a name="forecast-function"></a>

The ML-powered forecast computation forecasts future metrics based on patterns of previous metrics by seasonality. For example, you can create a computation to forecast total revenue for the next six months.

To use this function, you need at least one dimension in the **Time** field well. 

For more information about working with forecasts, see [Forecasting and creating what-if scenarios with Amazon Quick Sight](forecasts-and-whatifs.md).

## Parameters
<a name="forecast-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

*Periods forward*   
The number of time periods in the future that you want to forecast. Ranges from 1 to 1,000.

*Periods backward*   
The number of time periods in the past that you want to base your forecast on. Ranges from 0 to 1,000.

*Seasonality*   
The number of seasons included in the calendar year. The default setting, **automatic** detects this for you. Ranges from 1 to 180.

## Computation outputs
<a name="forecast-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `metricValue` – The value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `timeValue` – The value in the date dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the date field.
+ `relativePeriodsToForecast` – The relative number of periods between latest datetime record and last forecast record.

# Growth rate computation
<a name="growth-rate-function"></a>

The growth rate computation compares values over time periods. For example, you can create a computation to find the three-month compounded growth rate for sales, expressed as a percentage.

To use this function, you need at least one dimension in the **Time** field well. 

## Parameters
<a name="growth-rate-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

*Number of periods*   
The number of time periods in the future that you want to use to compute the growth rate.

## Computation outputs
<a name="growth-rate-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `previousMetricValue` – The previous value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `previousTimeValue` – The previous value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `compoundedGrowthRate` – The percent difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the percent difference.
  + `formattedValue` – The formatted value of the percent difference (for example, -42%).
  + `formattedAbsoluteValue` – The formatted absolute value of the percent difference (for example, 42%).
+ `absoluteDifference` – The absolute difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the absolute difference.
  + `formattedValue` – The absolute difference formatted by the settings in the metric field's format preferences.
  + `formattedAbsoluteValue` – The absolute value of the difference formatted by the metric field.

# Maximum computation
<a name="maximum-function"></a>

The maximum computation finds the maximum dimension by value. For example, you can create a computation to find the month with the highest revenue. 

To use this function, you need at least one dimension in the **Time** field well. 

## Parameters
<a name="maximum-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

## Computation outputs
<a name="maximum-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 

**Note**  
These are the same output parameters as the ones that are returned by the minimum computation.
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `metricValue` – The value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `timeValue` – The value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.

# Metric comparison computation
<a name="metric-comparison-function"></a>

The metric comparison computation compares values in different measures. For example, you can create a computation to compare two values, such as actual sales compared to sales goals. 

To use this function, you need at least one dimension in the **Time** field well and at least two measures in the **Values** field well. 

## Parameters
<a name="metric-comparison-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

*Target value*   
The field that you want to compare to the value.

## Computation outputs
<a name="metric-comparison-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `fromMetricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `fromMetricValue` – The value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `toMetricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `toMetricValue` – The current value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `timeValue` – The value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `percentDifference` – The percent difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the percent difference.
  + `formattedValue` – The formatted value of the percent difference (for example, -42%).
  + `formattedAbsoluteValue` – The formatted absolute value of the percent difference (for example, 42%).
+ `absoluteDifference` – The absolute difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the absolute difference.
  + `formattedValue` – The absolute difference formatted by the settings in the metric field's format preferences.
  + `formattedAbsoluteValue` – The absolute value of the difference formatted by the metric field.

# Minimum computation
<a name="minimum-function"></a>

The minimum computation finds the minimum dimension by value. For example, you can create a computation to find the month with the lowest revenue. 

To use this function, you need at least one dimension in the **Time** field well. 

## Parameters
<a name="minimum-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank.

*Value*   
The aggregated measure that the computation is based on.

## Computation outputs
<a name="maximum-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 

**Note**  
These are the same output parameters as the ones that are returned by the maximum computation.
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `metricValue` – The value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `timeValue` – The value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.

# Period over period computation
<a name="period-over-period-function"></a>

The period over period computation compares values from two different time periods. For example, you can create a computation to find out how much sales increased or decreased since the previous time period. 

To use this function, you need at least one dimension in the **Time** field well. 

## Parameters
<a name="period-over-period-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank. 

*Value*   
The aggregated measure that the computation is based on. 

## Computation outputs
<a name="period-over-period-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `previousMetricValue` – The previous value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `previousTimeValue` – The previous value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `currentMetricValue` – The current value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `currentTimeValue` – The current value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `percentDifference` – The percent difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the percent difference.
  + `formattedValue` – The formatted value of the percent difference (for example, -42%).
  + `formattedAbsoluteValue` – The formatted absolute value of the percent difference (for example, 42%).
+ `absoluteDifference` – The absolute difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the absolute difference.
  + `formattedValue` – The absolute difference formatted by the settings in the metric field's format preferences.
  + `formattedAbsoluteValue` – The absolute value of the difference formatted by the metric field.

## Example
<a name="period-over-period-computation-example"></a>

**To create a Period over period computation**

1. In the analysis that you want to change, choose **Add insight**.

1. For **Computation type**, choose **Period over period**, and then choose **Select**.

1. In the new insight that you created, add the time dimension and value dimension fields that you want to compare. In the screenshot below, `Order Date` and `Sales (Sum)` are added to the insight. With these two fields selected, Quick Sight shows the year to date sales of the latest month and the percentage difference compared with the previous month.  
![\[alt text not found\]](http://docs.amazonaws.cn/en_us/quick/latest/userguide/images/periodOverPeriod1.png)

1. (Optional) To further customize the insight, open the on-visual menu and choose **Customize narrative**. In the **Edit narative** window that appears, drag and drop the fields that you need from the **Computations** list, and then choose **Save**.

# Period to date computation
<a name="period-to-date-function"></a>

The period to date computation evaluates values for a specified period to date. For example, you can create a computation to find out how much you've earned in year-to-date sales. 

To use this function, you need at least one dimension in the **Time** field well. 

## Parameters
<a name="period-to-date-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Date*   
The date dimension that you want to rank. 

*Value*   
The aggregated measure that the computation is based on. 

*Time granularity*   
The date granularity that you want to use for the computation, for example year to date.

## Computation outputs
<a name="period-to-date-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `timeField` – From the **Time** field well. 
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `metricField` – From the **Values** field well. 
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `previousMetricValue` – The previous value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `previousTimeValue` – The previous value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `currentMetricValue` – The current value in the metric dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
+ `currentTimeValue` – The current value in the datetime dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `periodGranularity` – The period granularity for this computation (**MONTH**, **YEAR**, and so on).
+ `percentDifference` – The percent difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the percent difference.
  + `formattedValue` – The formatted value of the percent difference (for example, -42%).
  + `formattedAbsoluteValue` – The formatted absolute value of the percent difference (for example, 42%).
+ `absoluteDifference` – The absolute difference between the current and previous values of the metric field.
  + `value` – The raw value of the calculation of the absolute difference.
  + `formattedValue` – The absolute difference formatted by the settings in the metric field's format preferences.
  + `formattedAbsoluteValue` – The absolute value of the difference formatted by the metric field.

## Example
<a name="period-to-date-computation-example"></a>

**To create a Period to date computation**

1. In the analysis that you want to change, choose **Add insight**.

1. For **Computation type**, choose **Period to date**, and then choose **Select**.

1. In the new insight that you created, add the time dimenstion and value dimension fields that you want to compare. In the screenshot below, `Order Date` and `Sales (Sum)` are added to the insight. With these two fields selected, Quick Sight shows the year to date sales of the latest month and the percentage difference compared with the previous month.  
![\[alt text not found\]](http://docs.amazonaws.cn/en_us/quick/latest/userguide/images/periodOverPeriod1.png)

1. (Optional) To further customize the insight, open the on-visual menu and choose **Customize narrative**. In the **Edit narative** window that appears, drag and drop the fields that you need from the **Computations** list, and then choose **Save**.

# Top movers computation
<a name="top-movers-function"></a>

The top movers computation counts the requested number of categories by date that rank in the top of the autonarrative's dataset. For example, you can create a computation to find the top products by sales revenue for a time period.

To use this function, you need at least one dimension in the **Time** field well and at least one dimension in the **Categories** field well. 

## Parameters
<a name="top-movers-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Category*   
The category dimension you want to rank. 

*Value*   
The aggregated measure that the computation is based on. 

*Number of results*   
The number of top ranking items you want to find.

## Computation outputs
<a name="top-movers-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 

**Note**  
These are the same output parameters as the ones that are returned by the bottom movers computation.
+ `timeField` – From the **Time** field well.
  + `name` – The formatted display name of the field.
  + `timeGranularity` – The time field granularity (**DAY**, **YEAR**, and so on).
+ `categoryField` – From the **Categories** field well.
  + `name` – The formatted display name of the field.
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `startTimeValue` – The value in the date dimension.
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the datetime field.
+ `endTimeValue` – The value in the date dimension.
  + `value` – The raw value.
  + `formattedValue` – The absolute value formatted by the datetime field.
+ `itemsCount` – The number of items included in this computation.
+ `items`: Top moving items.
  + `categoryField` – The category field.
    + `value` – The value (contents) of the category field.
    + `formattedValue` – The formatted value (contents) of the category field. If the field is null, this displays '`NULL`'. If the field is empty, it displays '`(empty)`'.
  + `currentMetricValue` – The current value for the metric field.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field.
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
  + `previousMetricValue` – The previous value for the metric field.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field.
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.
  + `percentDifference` – The percent difference between the current and previous values of the metric field.
    + `value` – The raw value of the calculation of the percent difference.
    + `formattedValue` – The formatted value of the percent difference (for example, -42%).
    + `formattedAbsoluteValue` – The formatted absolute value of the percent difference (for example, 42%).
  + `absoluteDifference` – The absolute difference between the current and previous values of the metric field.
    + `value` – The raw value of the calculation of the absolute difference.
    + `formattedValue` – The absolute difference formatted by the settings in the metric field's format preferences.
    + `formattedAbsoluteValue` – The absolute value of the difference formatted by the metric field.

# Top ranked computation
<a name="top-ranked-function"></a>

The top ranked computation finds the top ranking dimensions by value. For example, you can create a computation to find the top three states by sales revenue. 

To use this function, you need at least one dimension in the **Categories** field well. 

## Parameters
<a name="top-ranked-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Category*   
The category dimension that you want to rank. 

*Value*   
The aggregated measure that the computation is based on. 

*Number of results*   
The number of top ranking items that you want to find.

## Computation outputs
<a name="top-ranked-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 

**Note**  
These are the same output parameters as the ones that are returned by the bottom ranked computation.
+ `categoryField` – From the **Categories** field well.
  + `name` – The formatted display name of the field.
+ `metricField` – From the **Values** field well.
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `itemsCount` – The number of items included in this computation.
+ `items`: Top ranked items.
  + `categoryField` – The category field.
    + `value` – The value (contents) of the category field.
    + `formattedValue` – The formatted value (contents) of the category field. If the field is null, this displays '`NULL`'. If the field is empty, it displays '`(empty)`'.
  + `metricValue` – The metric field.
    + `value` – The raw value.
    + `formattedValue` – The value formatted by the metric field.
    + `formattedAbsoluteValue` – The absolute value formatted by the metric field.

# Total aggregation computation
<a name="total-aggregation-function"></a>

The total aggregation computation creates a grand total of the value. For example, you can create a computation to find the total revenue. 

To use this function, you need at least one dimension in the **Time** field well and at least one measure in the **Values** field well. 

## Parameters
<a name="total-aggregation-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Value*   
The aggregated measure that the computation is based on. 

## Computation outputs
<a name="total-aggregation-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `categoryField` – The category field. 
  + `name` – The display name of the category field.
+ `metricField` – From the **Values** field well. 
  + `name` – The formatted display name of the field.
  + `aggregationFunction` – The aggregation used for the metric (**SUM**, **AVG**, and so on).
+ `totalAggregate` – The total value of the metric aggregation. 
  + `value` – The raw value.
  + `formattedValue` – The value formatted by the metric field.
  + `formattedAbsoluteValue` – The absolute value formatted by the metric field.

# Unique values computation
<a name="unique-values-function"></a>

The unique values computation counts the unique values in a category field. For example, you can create a computation to count the number of unique values in a dimension, such as how many customers you have

To use this function, you need at least one dimension in the **Categories** field well. 

## Parameters
<a name="unique-values-function-parameters"></a>

*name*   
A unique descriptive name that you assign or change. A name is assigned if you don't create your own. You can edit this later.

*Category*   
The category dimension that you want to rank. 

## Computation outputs
<a name="unique-values-computation-outputs"></a>

Each function generates a set of output parameters. You can add these outputs to the autonarrative to customize what it displays. You can also add your own custom text. 

To locate the output parameters, open the **Computations** tab on the right, and locate the computation that you want to use. The names of the computations come from the name you provide when you create the insight. Choose the output parameter by clicking on it only once. If you click twice, you add the same output twice. Items displayed in **bold** can be used in the narrative. 
+ `categoryField` – The category field. 
  + `name` – The display name of the category field.
+ `uniqueGroupValuesCount` – The number of unique values included in this computation. 