# Tariffs Query Optimization

**URL:** <https://community.influxdata.com/t/tariffs-query-optimization/56884>\
**Category:** Fluxlang\
**Tags:** influxdb, flux, performance\
**Created:** [March 31, 2025, 8:48am UTC](https://community.influxdata.com/t/tariffs-query-optimization/56884 "2025-03-31T08:48:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcush](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@marcush](https://community.influxdata.com/u/marcush)\
**Post date:** [March 31, 2025, 8:48am UTC](https://community.influxdata.com/t/tariffs-query-optimization/56884/1 "2025-03-31T08:48:43Z")

</div>

I was wondering if anyone could help me optimize this query. I have a ‘tariffs’ table with a ‘rate’ field and tags including start hour, end hour, weekday, valid from and valid to. I need to join this with another table which has a ‘kWh’ field and multiply the kWh with the correct ‘rate’.

My query is below, it works okay for short windows but I need to be able to query data up to a year.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/9/0/907f85e0539db30b3d119c6fa5e9ac6595219c78.png)

Is there anything I can change with the query to make it more efficient or do I need to change the way I am approaching this?
