# Restrain select to time range!

Hello all, I have a query that returns some values from my influxdb with the power consumption. From the query I extract averages, min, max etc

This is the query to calculate the KWH
`SELECT sum("kwh") as "kwhd" FROM ( SELECT sum("watt") / 1000 * \$sample / 3600 as "kwh" FROM ( SELECT sum("power") as "watt" FROM "power" WHERE ("deviceId" =~ /^\$device\$/) AND \$timeFilter GROUP BY time(\$sample_s) ) WHERE \$timeFilter GROUP BY time(1h) ) WHERE \$timeFilter GROUP BY time(1d)`

The query works and this is the returned query inspector
`SELECT sum("kwh") as "kwhd" FROM ( SELECT sum("watt") / 1000 * 10 / 3600 as "kwh" FROM ( SELECT sum("power") as "watt" FROM "power" WHERE ("deviceId" =~ /^main\$/) AND time >= 1564614000000ms and time <= 1567292399999ms GROUP BY time(10s) ) WHERE time >= 1564614000000ms and time <= 1567292399999ms GROUP BY time(1h) ) WHERE time >= 1564614000000ms and time <= 1567292399999ms GROUP BY time(1d)`

And this the values

``````0:Array[1564531200000,0.485975]
1:Array[1564617600000,17.603391666666667]
2:Array[1564704000000,10.045136111111113]
3:Array[1564790400000,10.535122222222226]
4:Array[1564876800000,12.659838888888887]
5:Array[1564963200000,17.784555555555556]
6:Array[1565049600000,17.46396388888889]
7:Array[1565136000000,13.40831388888889]
8:Array[1565222400000,9.567997222222223]
9:Array[1565308800000,17.30015833333333]
10:Array[1565395200000,18.23287777777778]
11:Array[1565481600000,13.36856111111111]
12:Array[1565568000000,12.085250000000002]
13:Array[1565654400000,15.387980555555554]
14:Array[1565740800000,22.41155555555555]
15:Array[1565827200000,24.46866388888889]
16:Array[1565913600000,19.02095]
17:Array[1566000000000,21.250827777777776]
18:Array[1566086400000,26.663347222222225]
19:Array[1566172800000,null]
20:Array[1566259200000,null]
21:Array[1566345600000,null]
22:Array[1566432000000,null]
23:Array[1566518400000,null]
24:Array[1566604800000,null]
25:Array[1566691200000,null]
26:Array[1566777600000,null]
27:Array[1566864000000,null]
28:Array[1566950400000,null]
29:Array[1567036800000,null]
30:Array[1567123200000,null]
31:Array[1567209600000,null]
``````

My problem is the first record 0:Array[1564531200000,0.485975] Itâ€™s outside the set range, making that my Min for the last month for example is not correct

How can I restrain the data to the range?

Thank you