Friday, July 27, 2018

Re: [Question] Django 2 - how to sum values based on filter and group by Year-Month

On vrijdag 27 juli 2018 04:25:56 CEST Charles Sartori wrote:

> I need to Sum() the values filtering it with
> 1 - sum(values) where date < first day of the month
> 2 - sum(values) where date < last day of the month
>
> Expected result(something like that):
> [
> {'year-month': '2018-01'}, {'sum_before_month_day_one': *0*},
> {'sum_before_last_month_day': *60*},
> {'year-month': '2018-02'}, {'sum_before_month_day_one': *60*},
> {'sum_before_last_month_day': *70*},
> {'year-month': '2018-03'}, {'sum_before_month_day_one': *70*},
> {'sum_before_last_month_day': *100*},
> ]

Break it down:
- the only relevant part is the sum of the month
- the other is a running total you can keep track of without putting the
burdon on the database

But, requirement 2) applied to the first result should strictly yield 30, not
60. But I think that's an error in your requirement description.

> {'date': datetime.date(2018, 1, 1), 'quantity': 60.0}

(30 is *at* the last day of the month, not before it)
> 2018-01-31 30

--
Melvyn Sopacua


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2165075.IrKYnSaKcf%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment