This article shows how to add a calculate layer to a widget. The calculate layer is used in grid-type widgets when users want to display a column that computes a value using the other columns in the widget.
To add a calculate layer in a widget:
- Go to Widgets on the MSPbots menu.
- Click on the New Widget button.
- Click Grid on the New Widget window. You will be redirected to the Widget Builder.
- Provide the necessary info for this widget like the Name, Description, and Role, then click Apply.
- Click the Dataset icon, then click + button for Data Source.
-
Select New Layer on the Add New Layer window. Note that you must create the columns and measure before you can compute for the calculate layer.
-
In the Dataset window,
-
Select the dataset with the data you need.
- (Optional) Enter a datasource name in the Show datasource name as field.
-
For Columns Display
-
Go to the Column Name dropdown and select a field for the drill-through.
- Give it an Alias and select a Business Type for your selection.
-
Click the + button to add more rows.
-
Go to the Column Name dropdown and select a field for the drill-through.
-
Select the dataset with the data you need.
-
(Optional) Configuration for Filter
-
Click the + icon and choose either Add Condition or Add Group.
- Select all the fields you want to filter.
- Set conditions for each field using the two subsequent dropdown lists. For a guide on each option on the list, refer to the article What Filter Conditions and Formats are Available for Creating Widgets.
-
Select the logical operator AND or OR for the filter group.
-
Click the + icon and choose either Add Condition or Add Group.
-
Configuration for Measure
-
Click the + button corresponding to Measure.
-
When the Measure window opens, fill in the following fields:
-
Summarize Type - Select calculation methods.
- sum - Calculate the sum, for example, given a set of log time data: 8, 7.5, 9, 7.5, 9.5. The sum of log time values is 42.5.
- count - Count the occurrences, for example, counting the log time occurrences results in 5.
- avg - Calculate the average, for example, the average log time value is 8.5.
- max - Find the maximum value, for example, the maximum log time value is 9.5.
- min - Find the minimum value, for example, the minimum log time value is 7.5.
- string_agg - List all data, for example, listing all log time values: 8, 7.5, 9, 7.5, 9.5.
- (Optional) Separator - When the Summarize Type is string_agg, you can set the separator for the listed data, such as a comma ",".
- Fields - Select a calculation option. The options in the dropdown menu are values set as Alias in Column Display.
- Alias - Input a name for the metrics, automatically generated based on your choice of summary and fields.
-
(Optional) Format type - Select the data type for Measure, usually corresponding to the Business Type set in Step 7.c.
- Text
- Number
- Date
- Date Time
- Yes/No
- User
- If the default format does not meet your needs, you need to set the data format in advanced settings. Please click
to configure.
- Distinct - If this option is selected, duplicates will be automatically filtered out during calculations, considering unique data.
-
Summarize Type - Select calculation methods.
- Click Add.
-
Click the + button corresponding to Measure.
- Repeat Step 9 until you have all the measures for computing the Calculate Layer.
- Click Save.
- Click the + button and choose Calculate Layer to calculate the data of Measure.
-
On the Calculate Layer window, fill in the following fields to set up the calculate layer.
-
Name - Enter a unique name for the Calculate Layer.
Remember that the name of the Calculate Layer should not overlap with the Alias field of Measure. If they overlap, the settings of the calculation layer will not take effect. -
For Formula,
-
Please select the measure to be used for the formula.
When the Measure's Summarize Type is set to string_agg, do not add this measure to Formula. This is because the purpose of "string_agg" is to list data, and if set as a calculation layer, the data for this Measure will not display correctly. -
Input the formula in the box for the calculation layer.
-
For example, if you want to add 8 to the value of a certain Measure, you can click "+Measure," enter "+8" after "coalesce("Measure",0)" in the input box, and the formula will be "coalesce("Measure",0)+8."
-
For example, if you want to add 8 to the value of a certain Measure, you can click "+Measure," enter "+8" after "coalesce("Measure",0)" in the input box, and the formula will be "coalesce("Measure",0)+8."
-
-
-
-
If the default format does not meet your needs, you need to set the data format in advanced settings. Please click
to configure.
-
-
Name - Enter a unique name for the Calculate Layer.
- Once done, click Save then Apply. The Calculate Layer will now appear. The widget displays the values of the Measure and the values of the Calculate Layer.
If you want to create multiple calculation layers, repeat Steps 12, 13, and 14 to perform calculations on different data for Measures.