# 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 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.

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.

2. Click the Create metric button.

The metric editor dialog opens.

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:

5. 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:

1. Switch to the Analyze tab.

2. Switch the type of visualization to Column chart.

3. 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.

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

Your metric is now sliced into product categories.

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 metric editor opens.

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:

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.

You can now see both metrics in the column chart.

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