Skip to content
Advertisement

Select rows until running sum reaches specific value

I have the following data:

And a value such as 300 or 301 (a user variable or column). I want to select rows until running total of amount reaches the specified value, with the following twist:

  • For 300 I want to select first 3 rows for a and first 2 rows for b
  • For 301 I want to select first 4 rows for a and first 3 rows for b

This is supposed to be simple but the solutions I found do not handle the second case.

Advertisement

Answer

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