0
Hello. I need to create a Dashboard from a query. I would like to generate this column in the query always adding up to the previous month, ie a cumulative sum.
ex: instead of:
mês 1: 2
mês 2: 3
mês 3: 5
mês 4: 1
would be:
mês 1: 2
mês 2: 5
mês 3: 10
mês 4: 11
In my case:
SELECT count(id_produto) AS quantidade_ofertas, date_trunc(cast(datahora as date), month) as mes
FROM `TABELA1`
WHERE DATE(process_time) < CURRENT_DATE()
and cast(datahora as date) < CURRENT_DATE()
group by date_trunc(cast(datahora as date), month)
Being that in this code above, generates a column with values for each month, and not the sum to the previous one (cumulative).
The idea of this query is to generate a Dashboard where I can filter by date without the 'accumulative' that the ferally provides, disturb.
Thank you in advance.
wouldn’t just be changing the
count()
forsum()
?– Danizavtz
No. The sum would add up the product ids. What I tried to do was with: SELECT Count(id_product) AS quantity_ofertas, date_trunc(cast(datahora as date), Month) as mes FROM
TABELA1

WHERE DATE(process_time) < CURRENT_DATE()
and cast(datahora as date) < CURRENT_DATE()
group by date_trunc(cast(datahora as date), month)
SELECT sum(quantidade_ofertas) as cumulativo, mes
from TAB1
group by quantidade_ofertas, mes
order by mes asc
Only it gives the same result, because it adds up the same months. I want it gone the month before.– Diego Borges
I could do function composition, I’m without bigquery to test, but then you would do a sum(Count(id_product))
– Danizavtz
Retorno: Aggregations of aggregations are not allowed at [1:8]
– Diego Borges
It looks like you want to use a window Function: https://cloud.google.com/dataprep/docs/html/Window-Functions_57344749
– Thassyo Pereira