# Group daily values by month to align with utility bill

**URL:** <https://community.grafana.com/t/group-daily-values-by-month-to-align-with-utility-bill/110949>\
**Category:** InfluxDB\
**Tags:** influxql\
**Created:** [December 29, 2023, 5:32pm UTC](https://community.grafana.com/t/group-daily-values-by-month-to-align-with-utility-bill/110949 "2023-12-29T17:32:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![poldim](https://avatars.discourse-cdn.com/v4/letter/p/aca169/32.png) [@poldim](https://community.grafana.com/u/poldim)\
**Post date:** [December 29, 2023, 5:32pm UTC](https://community.grafana.com/t/group-daily-values-by-month-to-align-with-utility-bill/110949/1 "2023-12-29T17:32:53Z")

</div>

**I’m trying to group my daily gas usage to reflect what is shown in my monthly utility bills which cycle starts on the 13th of most months**

- What Grafana version and what operating system are you using?  
containerized at `grafana:latest` with `influxdb:1.8`
- **What** are you trying to achieve?  
Match grouping of daily values to a similar grouping as statements (from 13th to 12th)
- **How** are you trying to achieve it?  
Time series or bar chart with `GROUP BY = time (30d)`
- What happened?  
Groups by 30 days, but the total’s dont make sense. First 30d grouping shows sum of 17 while this is really the last 9 days of values.
- What did you **expect** to happen?  
30d grouping to sum 30 days. Is there a better way to group by month from 13th to 12th of every month?
- Can you copy/paste the configuration(s) that you are having problems with?  
`SELECT sum("value") FROM "therms" WHERE ("entity_id" = 'pge_daily_gas_usage') AND $timeFilter GROUP BY time($__interval) fill(none) tz('America/Los_Angeles')`

Charts shown here as bar charts just so values are visible for each day here. I’d prefer to run  
I’ve checked the daily values in influx and they match when the summing period is correct.  
This is the statement data from the utility:  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/9/49b92bbe4250ad1eebc9551483b07fe260ce5502.png)

Chart I’m working on:

- Why does this charts 30d group around the 19th through 24th? Is there a way to instruct or adjust when this happens?
- How can I group by month from 13th to 12th of every month?

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/0/f/0fb6674fd84003b00e001e05428bb1452f035714.png)

Changing it to daily grouping, looking at the last month:

- The last 9 days sum up to 17 instead of the last 30d as shown in the chart above  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/5/4/540805017c032f14948f7bb872877a5a9d4c7d3f.png)

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [December 29, 2023, 6:23pm UTC](https://community.grafana.com/t/group-daily-values-by-month-to-align-with-utility-bill/110949/2 "2023-12-29T18:23:18Z")

</div>

> [@poldim](#):
>
> How can I group by month from 13th to 12th of every month?

I do not believe there is a way in InfluxQL to group by month using a specific date range (e.g. start on 13th, end on 12th of following month).

If you are willing to change to & learn Flux, then I think simply aggregating by month with an offset value of 13 days would do the trick:

```auto
 |> aggregateWindow(every: 1mo, offset: 13d, fn: sum, timeSrc:"_start") 

```

More [here](https://docs.influxdata.com/flux/v0/stdlib/universe/aggregatewindow/). Using the `offset` parameter shifts the start of monthly windows to the desired day.
