sunnyphoenixier
Technical User
I am in the design phase of one project that requires currency conversions for multiple facts by using a currency exchange table. The difficulties I am having is that it feels like requires calculations across two fact tables. Here are the table structures:
Fact_Table
-------------------
Product_key
Department_key
Manufacture_Cost
Manufacture_cost_Currency_Code
Shipping_Cost
Shipping_Cost_Currency_Code
Storage_Cost
Storage_Cost_Currency_Code
Date
Currency_Exchange_Table
------------------
From_Currency_Code
To_Currency_Code
Rate_Effective_Start_Date
Rate_Effective_End_Date
Exchange_Rate
Notes:
1. As you can see, the key in Currency_Exchange_Table is the first 4 columns.
2. All conversions for all cost use the same Date column in the Fact_Table. The Date needs to fall inbetween of Rate_Effective_Start_Date and Rate_Effective_End_Date.
3. The To_Currency_Code is alwasys "USD".
4. The multiple currency codes in the Fact_Table are supposed to join to the From_Currency_Code in the Currency_Exchange_Table
5. The ideal SQL I am trying to get is
Select Product_Key,
Department_Key,
max(Manufacture_Cost*Exchange_Rate),
max(Shipping_Cost*Exchange_Rate),
max(Storage_Cost* Exchange_Rate)
from Fact_Table a11,
Currency_Exchange_Table a12,
Currency_Exchange_Table a13,
Currency_Exchange_Table a14
where a11.Manufacture_cost_Currency_Code = a12.From_Currency_Code
and a11.Shipping_Cost_Currency_Code = a13.From_Currency_Code
and a11.Storage_Cost_Currency_Code = a14.From_Currency_Code
and a12.Rate_Effective_End_Date <= a11.Date <= a12.Rate_Effective_Start_Date
and a13.Rate_Effective_End_Date <= a11.Date <= a13.Rate_Effective_Start_Date
and a14.Rate_Effective_End_Date <= a11.Date <= a14.Rate_Effective_Start_Date
Group by Product_Key,
Department_key
I am sure many of you have been through this situation. My questions to you are:
1. Is this a good model to attack the currency conversion problem?
2. If it is the model you use, what do you suggest for MSI Architect? What relationships do you create to ensure joins are correct?
3. Do you have a better approach to suggest?
Any suggestions are greatly appreciated!
Phoenixier
Fact_Table
-------------------
Product_key
Department_key
Manufacture_Cost
Manufacture_cost_Currency_Code
Shipping_Cost
Shipping_Cost_Currency_Code
Storage_Cost
Storage_Cost_Currency_Code
Date
Currency_Exchange_Table
------------------
From_Currency_Code
To_Currency_Code
Rate_Effective_Start_Date
Rate_Effective_End_Date
Exchange_Rate
Notes:
1. As you can see, the key in Currency_Exchange_Table is the first 4 columns.
2. All conversions for all cost use the same Date column in the Fact_Table. The Date needs to fall inbetween of Rate_Effective_Start_Date and Rate_Effective_End_Date.
3. The To_Currency_Code is alwasys "USD".
4. The multiple currency codes in the Fact_Table are supposed to join to the From_Currency_Code in the Currency_Exchange_Table
5. The ideal SQL I am trying to get is
Select Product_Key,
Department_Key,
max(Manufacture_Cost*Exchange_Rate),
max(Shipping_Cost*Exchange_Rate),
max(Storage_Cost* Exchange_Rate)
from Fact_Table a11,
Currency_Exchange_Table a12,
Currency_Exchange_Table a13,
Currency_Exchange_Table a14
where a11.Manufacture_cost_Currency_Code = a12.From_Currency_Code
and a11.Shipping_Cost_Currency_Code = a13.From_Currency_Code
and a11.Storage_Cost_Currency_Code = a14.From_Currency_Code
and a12.Rate_Effective_End_Date <= a11.Date <= a12.Rate_Effective_Start_Date
and a13.Rate_Effective_End_Date <= a11.Date <= a13.Rate_Effective_Start_Date
and a14.Rate_Effective_End_Date <= a11.Date <= a14.Rate_Effective_Start_Date
Group by Product_Key,
Department_key
I am sure many of you have been through this situation. My questions to you are:
1. Is this a good model to attack the currency conversion problem?
2. If it is the model you use, what do you suggest for MSI Architect? What relationships do you create to ensure joins are correct?
3. Do you have a better approach to suggest?
Any suggestions are greatly appreciated!
Phoenixier