# filter by month inside views dictionary

**URL:** <https://forum.djangoproject.com/t/filter-by-month-inside-views-dictionary/13749>\
**Category:** Using the ORM\
**Created:** [May 17, 2022, 6:38am UTC](https://forum.djangoproject.com/t/filter-by-month-inside-views-dictionary/13749 "2022-05-17T06:38:03Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 9, 2023, 1:12pm UTC](https://forum.djangoproject.com/t/filter-by-month-inside-views-dictionary/13749/21 "2023-03-09T13:12:10Z")

</div>

See the discussion and related links at [sum a grouped data](https://forum.djangoproject.com/t/sum-a-grouped-data/13915) to get some ideas.

---

<div class="post-metadata">

**Author:** ![adiraijamal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adiraijamal/32/12445_2.png) [@adiraijamal](https://forum.djangoproject.com/u/adiraijamal)\
**Post date:** [April 3, 2023, 5:39am UTC](https://forum.djangoproject.com/t/filter-by-month-inside-views-dictionary/13749/22 "2023-04-03T05:39:56Z")

</div>

```auto
totals = Transaction.objects.annotate(month=TruncMonth('trans_date')).values(
   'month', 'trans_mode').annotate(tot=Sum('trans_amount')).order_by()

```

brings the querset

```auto
{'totals': 
<QuerySet [
{'trans_mode': 'Cash', 'month': datetime.date(2023, 1, 1), 'tot': Decimal('99.25')}, 
{'trans_mode': 'Cash', 'month': datetime.date(2023, 2, 1), 'tot': Decimal('161.25')}, 
{'trans_mode': 'Cash', 'month': datetime.date(2023, 3, 1), 'tot': Decimal('40.5')}, 
{'trans_mode': 'ENBD', 'month': datetime.date(2023, 1, 1), 'tot': Decimal('2215.72000000000')}, 
{'trans_mode': 'ENBD', 'month': datetime.date(2023, 2, 1), 'tot': Decimal('1361.66000000000')}, 
{'trans_mode': 'ENBD', 'month': datetime.date(2023, 3, 1), 'tot': Decimal('-579.130000000000')}, 
{'trans_mode': 'NoL', 'month': datetime.date(2023, 1, 1), 'tot': Decimal('107')}, 
{'trans_mode': 'NoL', 'month': datetime.date(2023, 2, 1), 'tot': Decimal('56')}, 
{'trans_mode': 'NoL', 'month': datetime.date(2023, 3, 1), 'tot': Decimal('-69.5')}, 
{'trans_mode': 'Pay IT', 'month': datetime.date(2023, 1, 1), 'tot': Decimal('0')}, 
{'trans_mode': 'SIB', 'month': datetime.date(2023, 1, 1), 'tot': Decimal('208.390000000000')}, 
{'trans_mode': 'SIB', 'month': datetime.date(2023, 2, 1), 'tot': Decimal('-3.25')}
]>}

```

I need to iterate as below

| Trans Mode | Jan 2023 | Feb 2023 | Mar 2023 |
| --- | --- | --- | --- |
| Cash | 99.25 | 161.25 | 40.5 |
| ENBD | 2215.72 | 1361.66 | -579.13 |
| NoL | 107 | 56 | -69.5 |
| Pay IT | | | |
| SIB | 208.39 | -3.25 | |

show me some path for writing good HTML to achiever the above

[Previous page](https://forum.djangoproject.com/t/filter-by-month-inside-views-dictionary/13749.md?page=1)
