Data Analysis & SQL5.0 · 0 ratings
Currency And Unit Normalization For Reporting
Builds SQL to convert multi-currency or mixed-unit transactions to a single reporting basis with correct rates.
Role-BasedChain-of-ThoughtStructured-Output
Prompt
ROLE: You are a finance data analyst who consolidates multi-currency data into one reporting currency. CONTEXT: Transactions in [TRANSACTIONS_TABLE] carry amounts in their local currency (columns: amount, currency_code, transaction_date). Exchange rates live in [FX_RATES_TABLE] (currency_code, rate_to_[REPORTING_CURRENCY], rate_date). Engine: [DATABASE_ENGINE]. TASK: 1. Decide the rate-matching rule: use the rate effective on the transaction date (most recent rate on or before that date), not today's rate, and explain why for financial accuracy. 2. Write SQL that joins each transaction to the correct historical rate and converts to [REPORTING_CURRENCY]. 3. Handle missing rate dates by carrying forward the last known rate (as-of join) and flag any transaction with no available rate. 4. Aggregate converted amounts by [DIMENSION] and period. 5. Add a reconciliation check: converted totals by currency should sum to the grand total. OUTPUT FORMAT: Rate-matching rule -> Conversion ```sql``` (as-of join) -> Missing-rate handling -> Aggregation -> Reconciliation query. CONSTRAINTS: Never apply the current rate to historical transactions. Use the latest rate on or before the transaction date. Round only at the final reporting step, not per row, and state the rounding rule. Surface, do not silently drop, transactions lacking a rate.
Recommended models
claudegpt-4ogemini
More in Data Analysis & SQL
Translate Business Questions Into SQL
Turns a plain-English stakeholder question into a correct, well-commented SQL query against a known schema.
Read prompt
Optimize A Slow SQL Query
Diagnoses why a query is slow and rewrites it with targeted, explained optimizations and an index plan.
Read prompt
Debug A SQL Query That Returns Wrong Results
Systematically finds the logic error producing incorrect numbers and delivers a corrected, verified query.
Read prompt
Explain An Unfamiliar SQL Query In Plain English
Reverse-engineers a complex inherited query into a clear narrative, business meaning, and risk list.
Read prompt