@RavilN posted a new topic, subject "How to query the latest value efficiently". It read:

   Hi,  
    I am new to InfluxDB Flux, cannot figure out how to efficiently read the very last (current) values from the database. The values in my use case are written only if they change relative to the previously written value. So if for some variable value is not changed for a long time, then it would be out of display range (the query can be from Grafana or Chronograf, in both cases, it will have a range). And as a result, GUI widget (for example, gauge) will show that no data is available.
    
    If in the same dashboard to put widgets to display both current values ( in gauges) and history (in graphs), then I cannot select a wider range to include last changed value for a not changing variable. Because then it would take longer to process, and then history graphs would display data for time range which is out of interesting display range.  
    I looked at selectors like top or bottom, or last, but they must be used anyway with range option.  
    Is there any solution for this? Or I have to make sure that data values are written with some interval (minimum display interval?) even if they do not change?  
    Thank you, Ravil

Then @FixTestRepeat said

    RavilN:
    
    > I looked at selectors like top or bottom, or last, but they must be used anyway with range option.
    
    Can you post an example of the flux query you tried in a code </> block?
    
    I think you have two options :
    
      * make a continuous query/task that “upscales” the data so there's points at least every X minutes/seconds.
      * further extend the default time range bounds v.display to be wider for this specific measurement , and include the last filter like you mentioned

@RavilN replied

    Thank you your response.  
    I think probably the best option is to modify my data collecting agent (Visual Logger for OPC) optionally store data with some configurable maximum interval, even if is not changing.
    
    I wonder, would it be possible to add new feature into Flux, to pass additional parameter **returnBounds** , similar to the one used in OPC UA History Read requests as described here. In OPC UA, when this parameter is set to **true** , additionally to values within asked range also closest bounding values are returned. so if there are no data in the range, anyway values before and after the range can be returned.


{'source': 'discourse', 'url': 'https://community.influxdata.com/t/how-to-query-the-latest-value-efficiently/15210', 'title': 'How to query the latest value efficiently', 'views': 1010, 'has_accepted_answer': False, 'word_count': 416, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 3, 'tags': '', 'author': '@RavilN', 'participants': '@RavilN, @FixTestRepeat', 'image_url': [None], 'created_at': '2020-07-12T01:48:49.784Z', 'last_posted_at': '2020-07-13T20:10:57.544Z'}