in10: how to build a metric in a metric
Post on 13-Jun-2015
1.191 Views
Preview:
DESCRIPTION
TRANSCRIPT
in10
Using BY in MAQL
How to builda metric in a metric
with Petr Olmer, GoodData Evangelist
GoodData in10 with Petr Olmer: How to build a metric in a metric
What is a metric in a metric?
example 1: average monthly revenue
example 2: average number of new leads in a quarter
2
average from monthly numbers
total revenue for each month
average from quarterly numbers
number of new leads for each quarter
There are aggregationson two levels.
inner level (by month)
outer level
In most cases,the aggregations are different.
Exception:average of averages.
GoodData in10 with Petr Olmer: How to build a metric in a metric
Solution
average monthly revenue
average number of new leads in a quarter
3
average from monthly numbers
total revenue for each month
average from quarterly numbers
number of new leads for each quarter
Monthly Revenue:SELECT SUM(Revenue) BY Close Month/Year
Average Monthly Revenue:SELECT AVG(Monthly Revenue)
Quarterly Leads:SELECT COUNT(Lead) BY Created Quarter/Year
Average Quarterly Leads:SELECT AVG(Quarterly Leads)
GoodData in10 with Petr Olmer: How to build a metric in a metric
Solution in detail
4
Monthly Revenue:SELECT SUM(Revenue) BY Close Month/Year
Average Monthly Revenue:SELECT AVG(Monthly Revenue)
Outer metric is an aggregation of the inner metric.
Inner metric uses BY to define the aggregation level.
GoodData in10 with Petr Olmer: How to build a metric in a metric
You need to define the border between the inner aggregation and the outer one.
Why BY?
5
Without BY, the inner SUM would not knowwhere to stop and hand over to the outer AVG.
inner SUM outer AVG
BY Month
GoodData in10 with Petr Olmer: How to build a metric in a metric
Behind the scenes
6
inner SUM outer AVG
BY Month
$400K
datamart behind the scenesyour
report
Nov 2010 $450K
Dec 2010 $580K
Jan 2011 $320K
Feb 2011 $360K
March 2011 $430K
April 2011 $260K
GoodData in10 with Petr Olmer: How to build a metric in a metric
Behind the scenes
You’ve asked for one number and that’s what you get:Average monthly revenue
The monthly report is computed but you cannot see it.
7
Nov 2010 $450K
Dec 2010 $580K
Jan 2011 $320K
Feb 2011 $360K
March 2011 $430K
April 2011 $260K
$400K
datamart report behind the scenesyour
report
GoodData in10 with Petr Olmer: How to build a metric in a metric
Automatic (in-report) BY
You don’t need to use BY when the attribute is in the report.
8
Month/Year Revenue Monthly Revenue
Nov 2010 $450K $450K
Dec 2010 $580K $580K
Jan 2011 $320K $320K
Feb 2011 $360K $360K
March 2011 $430K $430K
April 2011 $260K $260K
Revenue:SELECT SUM(Revenue)
Monthly Revenue:SELECT SUM(Revenue) BY Month/Year
Both metrics return the same numbersbecause Month/Year attribute is in the report.
automatic BY
BY says: Include this attribute in the computation. But it’s already there!
GoodData in10 with Petr Olmer: How to build a metric in a metric
BY and BY
You can include more than one attribute in the BY clause.
You can have a metric in a metric in a metric in a...
9
SELECT SUM(Revenue) BY Month/Year, Department
It will return a number for each month and department.
Best Region Leads:SELECT MAX(Average Monthly/Region Leads)
Average Monthly/Region Leads:SELECT AVG(Month/Region Leads) BY Region
Month/Region Leads:SELECT COUNT(Lead) BY Month/Year, Region
one number for each month and region
one number for each region
one number only
GoodData in10 with Petr Olmer: How to build a metric in a metric
Off you go...
Find the border.
Put BY into the inner metric.
10
average from region numbers
total revenue for each region
SELECT SUM(Revenue) BY Region
top related