Create Metrics
While working directly with facts is possible to deliver basic analytics, you may want to create metrics to do more complex calculations. Metrics are custom made multidimensional queries that combine multiple facts and attributes. Metrics are saved to your workspace and can be reused in any number of visualisations. Metrics can also be used to calculate other metrics.
Examples of simple metrics might include:
Order Amount
←SUM(Quantity * Price)
Get the total value of all ordered products by multiplying the quantity of the ordered products by their price and summing it all up.
Revenue
←Order Amount where Order Status = "Delivered"
Get the revenue generated so far by filtering the Order Amount metric for orders that have been delivered.
Average Revenue per Customer
←AVG(Revenue by Customer ID)
Get the average revenue per customer by listing the Revenue metric per customer and taking the average.
Metrics are defined using Multidimensional Analytical Query Language (MAQL). MAQL is GoodData’s proprietary querying language. In this article we will go through several basic examples of how you can use MAQL to create your own metrics.
For a more in-depth introduction to MAQL we recommend you do the Getting Started with MAQL in GoodData.CN university course.
Create Your First Metric
You will create a metric called Order Amount
that will sum up the value of all of the ordered products.
Steps:
Switch to the Metrics tab.
Click Create metric.
The metric editor dialog opens.
Give the metric a title ‘Order Amount’ and a description ‘Total value of all ordered products’.
Copy and paste in the following MAQL query:
SELECT SUM({fact/price}*{fact/quantity})
Your metric definition should look like this:
Click Save.
You have just created your first metric. Note that you all your metrics are listed in this tab:
Use Your Metric In a Visualization
Now that you have created a metric, you can use it inside a visualization.
Steps:
Switch to the Analyze tab.
Switch the type of visualization to Column chart.
Drag and drop your metric
Order Amount
from the data catalog into the Metrics panel.You can now see your metric as in the column chart.
A single metric does not make for a very interesting visualizaiton. Let’s slice it by some attributes.
Drag and drop the
Category
attribute into the View by panel to slice the metricOrder Amount
by category.Your metric is now sliced into product categories.
Give your visualization a title ‘Order Value by Category’ and click Save.
Use a Metric to Create Another Metric
Use your previously created metric Order Amount
to create a new metric Revenue
, that will filter out any undilevered orders. Note that you can create a new metric on the go, without having to leave the Analyze tab.
Steps:
Click the Create metric button located in the bottom left-hand corner of the Analyze tab.
The metric editor opens.
Give the metric a title ‘Revenue’ and a description ‘Revenue from delivered products’.
Copy and paste in the following MAQL query:
SELECT {metric/order_amount} WHERE {label/order_status} = "Delivered"
Your metric definition should look like this:
Click Save in the metric dialog to save the metric.
Drag and drop your metric
Revenue
from the data catalog into the Metrics panel.You can now see both metrics in the column chart.
Rename your visualization to ‘Order Value vs Revenue by Category’ and click Save.