dosubot[bot] commented on issue #31365:
URL: https://github.com/apache/superset/issues/31365#issuecomment-2530454889

   <!-- Answer -->
   A similar issue was previously reported and resolved. The solution involves 
using the `get_time_filter` macro with the `remove_filter` parameter set to 
`True`. This approach ensures that the time filter is applied only within the 
virtual dataset and not on the outer query. Here's an example of how you can 
implement this:
   
   ```sql
   {% set time_filter = get_time_filter("bucket", remove_filter=True) %}
   {% set from_expr = time_filter.from_expr %}
   {% set to_expr = time_filter.to_expr %}
   {% set time_range = time_filter.time_range %}
   SELECT
     *,
     '{{ time_range }}' as time_range
   FROM west_Side_place_meter_channel_data_daily as mcdd
   JOIN Dashboard_Meter_Type_Channel_Configuration as dmtcc 
   ON dmtcc.channel_name = mcdd.channel_name 
   AND dmtcc.meter_type = mcdd.meter_type 
   AND dmtcc.unit_of_measurement = mcdd.unit_of_measurement
   WHERE dmtcc.meter_type = 'Electricity'
   {% if from_expr or to_expr %}AND 1 = 1
   {% if from_expr %}AND mcdd.bucket >= {{ from_expr }}{% endif %}
   {% if to_expr %}AND mcdd.bucket < {{ to_expr }}{% endif %}
   {% endif %}
   ```
   
   This configuration will apply the time filter only within the virtual 
dataset and prevent it from being applied again in the outer query 
<sup>[[1]](https://github.com/apache/superset/blob/master/docs/docs/configuration/sql-templating.mdx)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   
   ---
   <sup>Help Dosu learn! Give it feedback: [Great 
Response](https://app.dosu.dev/response-feedback/d386c9b0-a265-423e-940a-a19a4315d80b?feedback_type=great_response)
 | [Irrelevant 
Answer](https://app.dosu.dev/response-feedback/d386c9b0-a265-423e-940a-a19a4315d80b?feedback_type=irrelevant_answer)
 | [Incorrect 
Sources](https://app.dosu.dev/response-feedback/d386c9b0-a265-423e-940a-a19a4315d80b?feedback_type=incorrect_sources)
 | [Too 
Verbose](https://app.dosu.dev/response-feedback/d386c9b0-a265-423e-940a-a19a4315d80b?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/d386c9b0-a265-423e-940a-a19a4315d80b?feedback_type=hallucination)
 | 
[Other](https://app.dosu.dev/response-feedback/d386c9b0-a265-423e-940a-a19a4315d80b?feedback_type=other)</sup>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to