Skip to content
Advertisement

Sum of an adjacent column within a conditional range

I have a script that is trying to collate some census data.

The output is looking roughly like what i want, except there is a population column, and I want to sum the population column for each age bracket. Any thoughts?

I tried

But I get a ton of extra rows, like 20x as many so it’s not doing what I want, which is to add the sum of the populations of 18-23 and put them there and the sums of the population 24-35.

Thanks for any help!

Advertisement

Answer

You are correct in trying to setup conditional aggregation, but your logic is off. Try this version:

Note that we don’t need any subquery here.

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