Forum Discussion

Jensk's avatar
Jensk
Frequent Visitor
2 years ago
Solved

FX Rate calculation with a twist

I am building a balance sheet statement that I need to convert to USD. I have manipulated my data in a way that it always calculates the YTD amount depending on the column in the matrix. Now I need to convert these manipulated figures to USD.

 

My Data:

 

FACTTABLE (I added an Index column in the query):

DATEACCOUNTCURAMOUNTPERIODID
01-01-2024ReceivablesDKK10001
01-01-2024ReceivablesEUR101
01-01-2024ReceivablesUSD501
01-02-2024ReceivablesSEK100002
01-02-2024ReceivablesEUR202
01-02-2024ReceivablesUSD1602
01-03-2024ReceivablesGBP250003
01-03-2024ReceivablesEUR303
01-03-2024ReceivablesUSD2503
01-01-2024CashSEKSEK1000001
01-01-2024CashUSDUSD1001
01-01-2024CashGBPGBP10001

 

FXRATE

DateRateCurrency
01-01-20241,269036GBP
01-01-20240,096174SEK
01-01-20241,08313EUR
01-01-20240,145293DKK
01-01-20241,000000USD
01-02-20241,264798GBP
01-02-20240,096622SEK
01-02-20241,082626EUR
01-02-20240,145236DKK
01-02-20241,000000USD
01-03-20241,26183GBP
01-03-20240,093763SEK
01-03-20241,079144EUR
01-03-20240,144655DKK
01-03-20241,000000USD

 

My Raw Data looks like this:

 

To manipulate it I have made these changes:

  • Created a table PERIOD:

 

 

 

PERIOD = 
SELECTCOLUMNS(
    GENERATESERIES(0, 12, 1),
    "PERIOD_ID_ALL", [Value]
)​

 

 

 

  • Then in order to calculate a value in fields that are blank I create: CrossJoin_Table = CROSSJOIN(FACTTABLE,PERIOD)
  • In  CrossJoin_Table I add these two calculated columns:

 

 

 

CrossjoinBalance = 
CALCULATE(
    SUM(FACTTABLE[AMOUNT]),
    FILTER(
        FACTTABLE,
        FACTTABLE[PERIODID] = CrossJoin_Table[PERIOD_ID_ALL]
            && FACTTABLE[Index] = CrossJoin_Table[Index]
    )
)
CrossjoinBalAcc = 
VAR CurrentPeriod = CrossJoin_Table[PERIOD_ID_ALL]
VAR Index = CrossJoin_Table[Index]
VAR FilteredTable =
    FILTER(
        CrossJoin_Table,
        CrossJoin_Table[PERIOD_ID_ALL] <= CurrentPeriod
            &&  Index = CrossJoin_Table[Index]
    )
RETURN
    CALCULATE( SUM(CrossJoin_Table[CrossjoinBalance]),
    FilteredTable
    )

 

 

 

 

This results in this layout of my data where I use CrossJoin_Table[ACCOUNT] as rows, CrossJoin_Table[PERIOD_ID_ALL] as columns and CrossJoin_Table[CrossjoinBalAcc] (sum):

 

For each column in the table I get the correct YTD amount for that period (ie. Receivables for period 2 = 1060+10180 = 11240) and if nothing was added during the month the previous month carries over.

 

My Data Model:

 

 

So far so good ğŸ˜….

 

Now I need to implement a currency calculation layer on top of this while maintaining this layout. 

 

The Raw data by currency looks like this:

 

 

For period 1 I would need to make this calculation:

  • CashSEK = 100000*0,096174 (FX rate for SEK to USD for period 1 (January)) = 9617,40
  • Receivables = 1000*0,145293 + 10*1,08313 + 50 = 206,12

I need to do this for the YTD amount, which means that the column in the matrix should filter the FX rates used for the entire amount. So the 100000 SEK has one USD value in period 1, but a new USD value in period 2 and so on...

 

My Desired outcome:

 

Note that since I only have FX rates for the first 3 months of 2024 I have selected the march rates for periods 4 through 12 (this does not need to be taken into account).

 

Any tips to how I calculate this is greatly appreciated.

 

4 Replies

    • Jensk's avatar
      Jensk
      Frequent Visitor

      hi lbendlin 

       

      Thanks alot of the answer and file! I did indeed make an error with my data, sorry! Updated my desired outcome:

      Your file does not quite get the right result as it uses the march-rates for all amounts:

      But when I make a relation on Date between the Dates and FX tables in your file I gets the correct amounts 👌:

       

      I have an issue when incorporating it into my own file. I need to have 13 period columns which is why I use the period_id instead of months as columns. Period 0 is the previous year carrying over. I cannot use month as columns because 01-01-2024 can be in both period 0 and period 1.

       

      I tried incorporating your solution in my own file which I could not make work:

      https://drive.google.com/file/d/1gNn7MqPnd25qSEpukG-c91e72w1SXPH1/view?usp=sharing 

       

      How would you approach it if more data was added to your file and you had data in all 13 periods (0 through 12)?

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        I still don't understand why you would need a crossjoin table.  You can do the crossjoin in the visual.

         

        Please provide sample data that fully covers your issue.
        Please show the expected outcome based on the sample data you provided.