i2tutorials

Amazon QuickSight – Adding Calculated Fields

Amazon QuickSight – Adding Calculated Fields

 

Adding calculated fields to an analysis


An analysis can be enhanced by adding a calculated field

  1. Choose Add at the top left of your analysis, then select Add calculated field.
    1. Follow these steps in the calculations editor that opens
    2. The calculated field should have a name.
    3. You can use fields from your dataset, functions, and operators to create a formula.
  2. Choose Save when you are finished.

Adding calculated fields to a dataset

Calculated fields can be added directly to a dataset. Anyone who uses the dataset can access the fields you add. Additional calculated fields can be added to the dataset when used in an analysis. Adding fields to an analysis makes them available only to that analysis.

A calculated field can be added or edited for a dataset

 

The statement should read, “If the sale happened during this year, show the total sales, otherwise, show 0.”

To Open the Functions list and add the ifelse function. To close the list of all functions, select All. The function groups should now appear: Aggregate, Conditional, Date, etc.

To add ifelse to the workspace, choose Conditional and then double-click it.

To add the dateDiff function to the first empty line of the ifelse statement, simply double-click on it.

Optionally, include some spaces for better readability. Your expression should resemble the following example:

dateDiff(dateField, truncDate("YYYY", now()), "YYYY")

Replace dateField with the actual name of the date field in your dataset.

To create a field for TotalSales for last year, you can change 0 to 1.

An alternative method involves using addDateTime instead of truncDate. For each previous year, you modify the first parameter for addDateTime to represent each year. In this case, use -1 for last year, -2 for the year before that, and so on. If you employ addDateTime, maintain the dateDiff function at 0 for each year.

Replace {Date} and {Discharge Date} with the actual names of the date fields in your dataset.

For the then part of the ifelse statement, we need to select the measure (metric) that contains the sales amount, TotalSales.

To select a field, open the Fields list and double-click a field to add it to the workspace. Alternatively, you can type the name. Enclose names containing spaces with curly braces { }. Your metric might have a different name. You can identify a metric by the number sign (#) in front of it.

Your expression should now resemble the following:

 

We set the else part of the ifelse to 0. As a result, this field has a value of 0 for rows containing sales from previous years.

 

To accomplish this, add a comma on the blank line followed by a 0. If you included the comment at the beginning, your completed ifelse expression should appear as follows:

 

 

 

Exit mobile version