Skip to content
Advertisement

BigQuery – Solving a basic grouping/ aggregation error

I wish to output a sum of revenue per year per product, but also include a column with the year of introduction of each product (based on date first ordered).

I can not figure out what I am doing wrong here as I can do each calculation separately but not it seems within the same query, I am sure this is a basic misunderstanding of grouping or aggregation but I can not figure it out.

The year_intro will always be one value per sku

I think I want year_intro2 which gives me the error.

year_intro1 works but just picks up the min value within each revenue year (as below).

The desired output for c12345 year_intro has a value of 2019 for all year_order values.

enter image description here

Advertisement

Answer

Consider below approach

if applied to sample data in your question – output is

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement