feat: Dynamic currency
SUMMARY
Adds dynamic currency detection for chart formatting. When a metric's currency is set to "Auto-detect", Superset queries the dataset's designated currency code column to determine the appropriate currency symbol.
How it works:
- Dataset owners configure a
currency_code_column(e.g., a column containing "USD", "EUR", "GBP") - When building a chart, users select "Auto-detect" in the currency format dropdown
- Backend detects the currency from filtered data:
- Single currency → formats with that currency symbol
- Mixed currencies → falls back to neutral numeric formatting
Key changes:
Backend:
- Added
currency_code_columnfield to SqlaTable model with DB migration - Added
detect_currency()utility that queries distinct currencies from filtered data - Integrated currency detection into both QueryContext API and legacy viz API
- Returns
detected_currencyin API response for frontend consumption
Frontend:
- Added "Auto-detect" option to CurrencyControl (only shown when dataset has currency_code_column)
- Updated chart plugins to handle AUTO currency resolution: Timeseries, MixedTimeseries, BigNumber variants, Table, PivotTable, Heatmap, Sunburst, Treemap, Pie, Funnel, Gauge
- Refactored DatasourceEditor: moved
main_dttm_colfrom inline radio buttons to a new "Default Column Settings" section alongsidecurrency_code_column
Example data:
- Added
international_salesexample dataset demonstrating multi-currency transactions across regions
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Requires screenshot of:
-
Currency code column
-
Currency control dropdown with "Auto-detect" option + Chart displaying auto-detected currency formatting
TESTING INSTRUCTIONS
- Open the
international_salesdataset and set "Currency code column" tocurrency_code - Create a new chart (e.g., Big Number Total) using this dataset
- Select a numeric metric (e.g.,
revenue) - In the "Number Format" section, set currency to "Auto-detect"
- Apply filters to show single-currency data (e.g., filter by
country = USA) - Verify the chart displays USD formatting
- Change filter to show mixed currencies (e.g., all countries)
- Verify the chart falls back to neutral number formatting
ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [x] Changes UI
- [x] Includes DB Migration (follow approval process in SIP-193)
- [x] Migration is atomic, supports rollback & is backwards-compatible
- [x] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
- Open the
CodeAnt-AI Description
Auto-detect currency from dataset and per-row for chart formatting
What Changed
- Charts can use "Auto-detect" currency: when a dataset defines a currency code column, selecting Auto-detect formats values with the dataset’s currency (or a per-row currency for tables/pivot tables) instead of a fixed symbol.
- Table and PivotTable now perform per-cell currency detection when Auto-detect is selected and the currency column is included in query results; mixed-currency rows fall back to neutral numeric formatting.
- The backend returns a detected_currency value for chart queries; other chart types (timeseries, big number, pie, heatmap, treemap, gauge, etc.) use this dataset-level detection as a fallback when per-row data is not available.
- Currency selector in controls shows an "Auto-detect" option only when the current dataset has a configured currency code column and moves that option to the top of the list.
- Dataset editor exposes a "Default Column Settings" area to pick the currency code column (string columns only) and stores it on datasets; a DB migration and example dataset demonstrating multi-currency data were added.
- Currency formatting behavior: AUTO mode now uses row context when available, then backend-detected currency, and finally neutral formatting for mixed or missing currencies; numerous tests added to cover these cases.
Impact
✅ Clearer currency symbols in charts when dataset provides a currency column
✅ Fewer mixed-currency formatting errors (mixed rows now show neutral numbers)
✅ Auto-detect option only appears when it will work for the selected dataset
💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
@codeant-ai ask: Your question here
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
@codeant-ai ask: Can you suggest a safer alternative to storing this secret?
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
@codeant-ai: Your feedback here
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
@codeant-ai: Do not flag unused imports.
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
@codeant-ai: review
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
CodeAnt AI is reviewing your PR.
Nitpicks 🔍
| 🔒 No security issues identified |
⚡ Recommended areas for review
|
CodeAnt AI finished reviewing your PR.
Codecov Report
:x: Patch coverage is 27.33813% with 101 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 67.73%. Comparing base (4f3403b) to head (2a9bafe).
:warning: Report is 215 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #36416 +/- ##
===========================================
+ Coverage 0 67.73% +67.73%
===========================================
Files 0 644 +644
Lines 0 48214 +48214
Branches 0 5284 +5284
===========================================
+ Hits 0 32660 +32660
- Misses 0 14263 +14263
- Partials 0 1291 +1291
| Flag | Coverage Δ | |
|---|---|---|
| hive | 42.76% <14.38%> (?) |
|
| mysql | 65.76% <27.33%> (?) |
|
| postgres | 65.81% <27.33%> (?) |
|
| presto | 46.36% <25.17%> (?) |
|
| python | 67.70% <27.33%> (?) |
|
| sqlite | 65.53% <27.33%> (?) |
|
| unit | 100.00% <ø> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
CodeAnt AI is running Incremental review
CodeAnt AI is running Incremental review
CodeAnt AI is running Incremental review
@richardfogaca let's change the label in the dropdown from "Auto-detect from dataset" to "Auto-detect" so that it fits nicely :)
Hi @kasiazjc, sorry that screenshot is outdated, I have already updated the label to "Auto-detect" all good, thanks! :)
Hi @kasiazjc, sorry that screenshot is outdated, I have already updated the label to "Auto-detect" all good, thanks! :)
perfect, thank you! 🫶
Taking a look, but just wanted to mention that this is a really big PR... next time it would be better to use stacked diffs to make the review easier and faster. 😄
CodeAnt AI is running Incremental review
Hi @betodealmeida, I didn't know about that. It does seem quite helpful for these cases, I'll make sure I use it next time. Thanks for the tip
🎪 Showtime deployed environment on GHA for f0165e5
• Environment: http://44.255.20.214:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically
CodeAnt AI is running Incremental review