Alexandre Hermann
03/05/2024, 8:20 PMSELECT SUM(Numerator) / SUM(Denominator)
Where Numerator and Denominator are sub queries ?Jakub Sterba
03/05/2024, 8:43 PMselect sum({fact/value} * {fact/weight}) / sum({fact/weight})
In case you need to calculate value as metric you may need to specify grain at which it is calculated. For example following MAQL
select sum(select {metric/value} * {metric/weight} by label/date.day) / sum(select {metric/weight} by label/date.day)
will calculate value and weight for each day as interim step and then the weighted average will be computed.Jakub Sterba
03/05/2024, 8:52 PMselect {fact/value} * {fact/weight}
Denominator
select {fact/weight}
can be used in
SELECT SUM(metric/Numerator) / SUM(metric/Denominator)
or
Numerator:
select {metric/value} * {metric/weight} by label/date.day
Denominator
select {metric/weight} by label/date.day
can be used in
SELECT SUM(metric/Numerator) / SUM(metric/Denominator)
Alexandre Hermann
03/05/2024, 8:52 PMSELECT (
SUM(SELECT{fact/private_metric_mqlCount.value} * {fact/private_metric_mqlToSQL.value} by {label/Metric_Date.month}) /
SUM (SELECT{fact/private_metric_mqlCount.value} by {label/Metric_Date.month})
)
Alexandre Hermann
03/05/2024, 8:53 PM{
"title": "Bad Request",
"status": 400,
"detail": "A result cache error has occurred during the calculation of the result",
"resultId": "a8de28ed2bc07fc1439e26fcd3be822d2417fe9b",
"reason": "Antichain='[attribute/private_metric_mqlCount.Metric_ID/06f46a2becd6468ca7f54e34db0ee38c, attribute/private_metric_mqlToSQL.Metric_ID/06f46a2becd6468ca7f54e34db0ee38c]' has no witness",
"traceId": "8b3abb647b0826e00bd493f3149c8435"
}
Alexandre Hermann
03/05/2024, 8:55 PMAlexandre Hermann
03/05/2024, 8:56 PMAlexandre Hermann
03/05/2024, 8:56 PMJakub Sterba
03/05/2024, 8:57 PMselect fact/private_metric_mqlCount.value by {label/Metric_Date.month}
Fact table may contain multiple facts for each month. You need to specify aggregation how to reduce number of facts to single value per month.
E.g.
select sum(fact/private_metric_mqlCount.value) by {label/Metric_Date.month}
or you can decompose it and make metric1:
select sum(fact/private_metric_mqlCount.value)
and reference it from the other metric
select {metric/metric1} by {label/Metric_Date.month}
Jakub Sterba
03/05/2024, 8:58 PMAlexandre Hermann
03/05/2024, 9:01 PMJakub Sterba
03/05/2024, 9:04 PMAlexandre Hermann
03/05/2024, 9:04 PMAlexandre Hermann
03/05/2024, 9:05 PMSELECT (
SUM(SELECT{metric/mql_count_forecast} * {metric/mql_to_sql_forecast} by {label/Metric_Date.month}) /
SUM (SELECT {metric/mql_count_forecast} by {label/Metric_Date.month})
)
Alexandre Hermann
03/05/2024, 9:06 PMJakub Sterba
03/05/2024, 9:09 PMSELECT (
SUM(SELECT{metric/mql_count_forecast} * {metric/mql_to_sql_forecast} by {label/Metric_Date.month},{label/funnel},{label/channel}) /
SUM (SELECT {metric/mql_count_forecast} by {label/Metric_Date.month},{label/funnel},{label/channel})
)
The finer grain will make individual values smaller and thus also result of weighted average. Common dimensions can be used also for slicing of the result so you can calculate weighted average per funnel or per channel or per pair (funnel,channel).Jakub Sterba
03/05/2024, 9:12 PMAlexandre Hermann
03/05/2024, 9:16 PMAlexandre Hermann
03/05/2024, 9:19 PMAlexandre Hermann
03/05/2024, 9:19 PMJakub Sterba
03/05/2024, 9:20 PMAlexandre Hermann
03/05/2024, 9:21 PM