inazr opened a new issue, #35815:
URL: https://github.com/apache/superset/issues/35815

   ### Bug description
   
   If I create a bar chart with the option `Group remaining as "Others"` 
enabled, the selected filters no longer apply due to an incorrect SQL query. 
   
   <img width="401" height="849" alt="Image" 
src="https://github.com/user-attachments/assets/c533a485-cfb9-4b02-90d3-8a903867321f";
 /> 
   
   This is the SQL code with the option disabled: 
   
   ```
   SELECT
     DATE_TRUNC(creation_date, DAY) AS creation_date,
     destination_table_id AS destination_table_id,
     sum(total_costs) AS SUM_total_costs__c069f
   FROM 
project_id.stg_bigquery_metadata.stg_bigquery_metadata__costs_per_table_per_user
   JOIN (
     SELECT
       destination_table_id AS destination_table_id__,
       sum(total_costs) AS mme_inner__
     FROM 
project_id.stg_bigquery_metadata.stg_bigquery_metadata__costs_per_table_per_user
     WHERE
       creation_date >= CAST('2025-09-25' AS DATE)
       AND creation_date < CAST('2025-10-24' AS DATE)
     GROUP BY
       destination_table_id__
     ORDER BY
       sum(total_costs) DESC
     LIMIT 10
   ) AS series_limit
     ON destination_table_id = destination_table_id__
   WHERE
     creation_date >= CAST('2025-09-25' AS DATE)
     AND creation_date < CAST('2025-10-24' AS DATE)
   GROUP BY
     creation_date,
     destination_table_id
   ORDER BY
     SUM_total_costs__c069f DESC
   LIMIT 10000
   ```
   
   If I enable the option, the following code is generated:
   
   ```
   SELECT
     DATE_TRUNC(creation_date, DAY) AS creation_date,
     CASE
       WHEN (
         NOT series_limit.destination_table_id__ IS NULL
       )
       THEN destination_table_id
       ELSE 'Others'
     END AS destination_table_id,
     sum(total_costs) AS SUM_total_costs__c069f
   FROM 
project_id.stg_bigquery_metadata.stg_bigquery_metadata__costs_per_table_per_user
   LEFT OUTER JOIN (
     SELECT
       destination_table_id AS destination_table_id__,
       sum(total_costs) AS mme_inner__
     FROM 
project_id.stg_bigquery_metadata.stg_bigquery_metadata__costs_per_table_per_user
     WHERE
       creation_date >= CAST('2025-09-25' AS DATE)
       AND creation_date < CAST('2025-10-24' AS DATE)
     GROUP BY
       destination_table_id__
     ORDER BY
       sum(total_costs) DESC
     LIMIT 10
   ) AS series_limit
     ON destination_table_id = destination_table_id__
   GROUP BY
     creation_date,
     CASE
       WHEN (
         NOT series_limit.destination_table_id__ IS NULL
       )
       THEN destination_table_id
       ELSE 'Others'
     END
   ```
    
   The second (= outer) WHERE clause is missing and therefor the chart is not 
filtered to the selected time period.
   
   
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   I don't know
   
   ### Node version
   
   I don't know
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [ ] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to