GitHub user dosubot[bot] added a comment to the discussion: Export chart to 
.CSV\.ODS

<!-- Answer -->
To export a table/chart in Superset and ensure the exported data matches what 
you see in the UI, your form_data (or query_context) must include these 
required fields: datasource (formatted as 
`<datasource_id>__<datasource_type>`), queries (an array of query objects), and 
viz_type. Missing these will cause errors like "Empty query" or export 
irrelevant data ([source](https://github.com/apache/superset/pull/35798), 
[source](https://github.com/apache/superset/blob/master/superset/commands/explore/get.py)).

To match the exported data to your table, make sure form_data includes the same 
filters, columns, metrics, and especially the row_limit as used in the UI. If 
you want to export only the visible rows (e.g., 25), set row_limit to 25; if 
you want all data, set it to a high value. Any mismatch here will cause the 
exported file to have more or fewer rows than expected 
([source](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx)).

Fields in form_data that directly affect the export include: datasource, 
viz_type, columns, metrics, filters, orderby, row_limit, and query_mode. These 
are extracted and normalized by Superset's query logic 
([source](https://github.com/apache/superset-frontend/packages/superset-ui-core/src/query/extractQueryFields.ts)).

If you pass form_data directly to the export endpoint, ensure it is not empty 
and contains all the above fields. Also, include datasource_id and 
datasource_type as top-level fields in your API request 
([source](https://github.com/apache/superset/blob/master/superset/explore/form_data/schemas.py)).

In summary: always use the exact form_data that was used to build the table, 
with the correct datasource, viz_type, filters, and row_limit, to avoid empty 
queries and row count mismatches.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/f3e3fa3e-8d3e-4251-94bc-08a13d5c965a?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat
 with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&
 nbsp;[![Join 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/35846)

GitHub link: 
https://github.com/apache/superset/discussions/35846#discussioncomment-14783742

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


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

Reply via email to