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 AmountSUM(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.

  • RevenueOrder 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 CustomerAVG(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:

  1. Switch to the Metrics tab.

    Switch to the metrics tab
  2. Click Create metric.

    Click Create metric

    The metric editor dialog opens.

    Empty editor
  3. Give the metric a title ‘Order Amount’ and a description ‘Total value of all ordered products’.

  4. Copy and paste in the following MAQL query:

    SELECT SUM({fact/price}*{fact/quantity})
    

    Your metric definition should look like this:

    Metric defined
  5. Click Save.

    You have just created your first metric. Note that you all your metrics are listed in this tab:

    Metric listed

Use Your Metric In a Visualization

Now that you have created a metric, you can use it inside a visualization.

Steps:

  1. Switch to the Analyze tab.

    Switch to the Analyze tab
  2. Switch the type of visualization to Column chart.

    Switch to the Column chart
  3. Drag and drop your metric Order Amount from the data catalog into the Metrics panel.

    Drag and drop metric

    You can now see your metric as in the column chart.

    Just order amount

    A single metric does not make for a very interesting visualizaiton. Let’s slice it by some attributes.

  4. Drag and drop the Category attribute into the View by panel to slice the metric Order Amount by category.

    Drag and drop attribute

    Your metric is now sliced into product categories.

    Slices by category
  5. 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:

  1. Click the Create metric button located in the bottom left-hand corner of the Analyze tab.

    The Create Metric button in the Analyze tab

    The metric editor opens.

    Metric editor in AD
  2. Give the metric a title ‘Revenue’ and a description ‘Revenue from delivered products’.

  3. Copy and paste in the following MAQL query:

    SELECT {metric/order_amount} WHERE {label/order_status} = "Delivered"
    

    Your metric definition should look like this:

    Revenue metric definiton
  4. Click Save in the metric dialog to save the metric.

  5. Drag and drop your metric Revenue from the data catalog into the Metrics panel.

    Drag and drop second metric

    You can now see both metrics in the column chart.

    Order Amount and Revenue Combined
  6. Rename your visualization to ‘Order Value vs Revenue by Category’ and click Save.