Solved

# Building of an MAQL for Rolling Average

• 7 replies
• 234 views

• New Participant
• 3 replies

We have a table with several records where we need to perform the moving average of the last 90 days considering only grouping by one column (fluxo_id_card).

If we don't consider the rolling avarage, the calculation is performed as follows:

But what happens is that we need to display these results in a month-to-month progression, where each month we view the average of the last 90 days.

For the Rolling average, the basic syntax is:

But we donâ€™t have a certain number of lines that each card would occupy, and that Rows Between doesÂ not currently support the COUNT function.

How can we adapt this calculation to the new context without changing the original table in the model?

icon

Best answer by Augusto Silva 14 March 2022, 14:24

View original

### 7 replies

Userlevel 3

Hey Augusto,

Â

First of all, I'd like to know, how do you plan to filter your report/metric for this 90 days period?Â Should it affect the whole table, please?

Have you tried to to build your RUNAVG metric as navigatedÂ hereÂ and simply lock it via theÂ BYÂ clause?

Hi Iva, sorry for the late answer, I was in an end-of-year recess.

Â

First of all, we cannot alter our original tables, because other reports depend onÂ this tables. We tought about making a series of math operations to achieve a final result.

Following I attached some prints to explain what we plan to do:

For the present data, we would select just the data of the last 90 days, per example, on 2022-03-01, only the data from 2022-01-01, 02-01 and 03-01 would be selected and summed for the same Id Card, and on 2022-04-01, only the data from 02-01, 03-01 and 04-01 would be selected and summed, taking in consideration the IdCard. This sum is the QtHours for each Id Card.

Â In the next step, we would take the average of the Qt Hours for the Reference month. So, for 2022-03-01, we would take the Average of 122, 108 and 59, and for 2022-04-01, we would take the average of 122, 119 and 80.

And in the next step, we just take these Metric Results and build some reports with them. On the following image, the Report examples are a Headline for the Present Reference Month (107, April), and a Line Chart with the values and the months.

Â

Â

Att.

Userlevel 3

Hey Augusto,

I've been informed by my colleagues that youÂ kindly attended ourÂ Office HoursÂ and that you were able to resolve your case byÂ buildingÂ some new metrics andÂ running average KPIs. Are you still hittingÂ some validation issues, please?

Hi Iva,

Â

Yes, they helped us, and we were able the finish the metric and find the values we were looking for. Thank you!Â

Userlevel 3

Those are awesome news, thank you for your confirmation.

Hi Augusto,Â

`I am trying to do something similar`
`Could you solve this?`

Â

Could you share how you did it?

Andres

Â

Â

Actually in Office Hours they helped us to undestand how the Average functions work in GoodData.
We calculated the Average of the time (hours) via the MAQL below, and divided by 24 (to find the value in days). But this value, Fluxo Tempo Qt Horas was calculated by a Python Scripy, that we ran in Airflow. It calculated the time between a card entered and left a column in our KanBan.
So the SLA for one column is the difference between a card entering and leaving it, and the average for that column, is the Average of the SLA. And to select just a time window, we put a filter in the dashboard, to select just thw preferredt ime.

Â

Â