Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
toBeTaughtIfPos
Frequent Visitor

Historic Blended Fx rate - column self referencing help

Hi all,

First post, happy new year, and apologies if I miss critical info, appreciate anybody that tries to help with the mess below 😅.

 

Situation: Accounting for Leases in non-functional currency.

I'm trying to create a powerBI model, that takes accounting journals that are presented in a contract's currency, and will convert these to the appropriate functional currency value for the month in question. I created a model last year, that broadly did what I needed it to, but had trouble with my depreciation charge because I needed to calculate a blended FX rate in a calcualted colum that would allow the posted functional NBV to be depreciated to zero. This meant I was referencing the column I was trying to write a formula in to try and get the previous row's values for it - and PBI didn't like a calc'd column that was self referencing. I ended up doing a work around that was materially correct, but not right, which I am trying to remedy now.

Looking to understand if what I am looking to do is possible, and the best way to do this - I think probably in M code hence posting in this formum, or either a calc'd column or measure.

Ultimately, I will use the functional currency amounts in an aggregation to create subledgers by lease and identify what journals need to be posted each month. Would like to be able to publish this so it is accessible to people from the different markets and functions which I why I'm trying it in PBI, and I'm not familiar with other tools (SQL/Python etc) unfortunately - so if PBI isn't the one, I may have to accept the ideal solution isn't possible.

 

Assume I have two tables:

Table1: Data_Journals (please ignore the rightmost two column for now - these are what I want to add and are referred to below, but included here to save space/repetition)

MarketKnown AsEvent DateCategoryCurrency pair (Functional-Contract)Movement typeDescriptionRate to useContract currency AmountRelevant FX RateFunctional Currency Amount
1JSA0334/1/2019ROU AssetJMD-USDAdditionTransition take upClosing153649.29134.35442720643462.32
1JSA0334/30/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1202.58134.354427-161571.9468
1JSA0335/31/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1242.66134.354427-166956.8723
1JSA0336/30/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1202.58134.354427-161571.9468
1JSA0337/31/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1242.66134.354427-166956.8723
1JSA0338/31/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1242.66134.354427-166956.8723
1JSA0339/30/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1202.58134.354427-161571.9468
1JSA03310/1/2019ROU AssetJMD-USDAdditionRemeasurement of Lease LiabilityClosing-3893.65135.153399-526240.032
1JSA03310/31/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1209.59134.3325837-162487.3499
1JSA03311/30/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1170.57134.3325837-157245.6925
1JSA03312/31/2019ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1209.59134.3325837-162487.3499
1JSA0331/31/2020ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1209.59134.3325837-162487.3499
1JSA0332/29/2020ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1131.56134.3325837-152005.3784
1JSA0333/31/2020ROU AssetJMD-USDDepreciation ChargeRight of Use Asset depreciationBlended Historic Closing-1209.59134.3325837-162487.3499

and Table2: Lookup_FX_Rates_table

Currency Rate TypeCurrency PairPeriodValue
CurrentJMD-USD4/30/2019134.354427
CurrentJMD-USD5/31/2019136.351241
CurrentJMD-USD6/30/2019134.048257
CurrentJMD-USD7/31/2019127.991809
CurrentJMD-USD8/31/2019126.871352
CurrentJMD-USD9/30/2019126.807
CurrentJMD-USD10/31/2019135.153399
CurrentJMD-USD11/30/2019128.205128
CurrentJMD-USD12/31/2019125.015627
CurrentJMD-USD1/31/2020133.74348
CurrentJMD-USD2/29/2020132.766861
CurrentJMD-USD3/31/2020130.514226

 

In my PBI, there is a calendar table that creates the relationship between the event date from table1 and that month's closing fx rate in table2 using an end of month column in the calendar table.

 

In excel on a small scale with this data I can easily add the two columns I need to Data_Journals to calc the functional currency amounts needed (see the rightmost two columns in Table1 above). Where my formulas in those two columns are essentially (being the formulas in the top row which is dragged down):

  • Relevant FX Rate=IF(I2="Closing",SUMIFS(Lookup_FX_Rates_table!$E$2:$E$13,Lookup_FX_Rates_table!$C$2:$C$13,Data_Journals!F2,Lookup_FX_Rates_table!$D$2:$D$13,EOMONTH(Data_Journals!C2,0)),SUM($L$1:L1)/SUM($J$1:J1))
  • Functional Currency Amount=J2*K2

I am looking for the best solution for how to get the same result in PBI. It would need to be scalable - as I have a large number of journals, and it would be a part of that column, as the extract I have showed is just for ROU, I will have other lines with different categories that I am comfortable pulling the correct fx rate for to use in the calc within a calc'd column.

Incase the solution is in M, then essentially the column "Rate-to-use" defines which I need, either the closing for the currency pair, the average where both closing and average are specified already in the Lookup_FX_Rates_table - or the calculated blended historic closing which would be unique for each non functional currency lease.
Previously for closing and average, I had a separate table for each, Lookup_FX_Rates_table_Average & Lookup_FX_Rates_table_Closing, but I might try making just one table now if it is easier/cleaner.

 

Very sorry if this is unclear, if more info is required, I will try to share as best I can. Thanks in advance all.

Edit: Link to excel file:
PowerQuery Forum Help file - Blended historic FX rate.xlsx

1 ACCEPTED SOLUTION

Hi v-prasare, thanks for following up - I had to step away from this project briefly, but coming back to this now. appreciate your help to try and get a successful solution!

View solution in original post

17 REPLIES 17
v-prasare
Community Support
Community Support

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

 

If we don’t hear back, we’ll go ahead and close this thread. For any further discussions or questions, please start a new thread in the Microsoft Fabric Community Forum  we’ll be happy to assist.

Thank you for being part of the Microsoft Fabric Community.

v-prasare
Community Support
Community Support

@toBeTaughtIfPos, as we haven’t heard back from you, we wanted to check in to see if the resolution provided by our Supers User helps?

If you’re still facing any issues or have additional questions, please don’t hesitate to let us know.

We’re here to help and would be happy to assist further if needed. Looking forward to your feedback!

 

 

 

Thanks,

Prashanth Are

MS Fabric community support.

 

Did we answer your question? Mark post as a solution, this will help others!

If our response(s) assisted you in any way, don't forget to drop me a "Kudos"

Hi v-prasare, thanks for following up - I had to step away from this project briefly, but coming back to this now. appreciate your help to try and get a successful solution!

Thanks for the update @toBeTaughtIfPos

v-prasare
Community Support
Community Support

@toBeTaughtIfPos, as we haven’t heard back from you, we wanted to check in to see if the resolution provided by our Supers User helps?

If you’re still facing any issues or have additional questions, please don’t hesitate to let us know.

We’re here to help and would be happy to assist further if needed. Looking forward to your feedback!

 

 

 

Thanks,

Prashanth Are

MS Fabric community support.

 

Did we answer your question? Mark post as a solution, this will help others!

If our response(s) assisted you in any way, don't forget to drop me a "Kudos"

v-prasare
Community Support
Community Support

Hi @toBeTaughtIfPos,

Hope your doing well.

 

@lbendlin Thanks for your prompt response here.

 

@toBeTaughtIfPos, as we haven’t heard back from you, we wanted to check in to see if the resolution provided by our Supers User helps?

If you’re still facing any issues or have additional questions, please don’t hesitate to let us know.

We’re here to help and would be happy to assist further if needed. Looking forward to your feedback!

 

 

 

Thanks,

Prashanth Are

MS Fabric community support.

 

Did we answer your question? Mark post as a solution, this will help others!

If our response(s) assisted you in any way, don't forget to drop me a "Kudos"

lbendlin
Super User
Super User

Self referencing will never be possible in DAX.  In Power Query you can sometimes emulate it with List.Accumulate.

 

How is 134.3325837  calculated?  Average of what?

 

 

Hey, Thanks for the reply.

 

Great question, hopefully the below picture better shows it, I simplified the formula from the post to make it clearer for the screenshot.

toBeTaughtIfPos_0-1736448071904.png

 

I'm still not following. What's the formula in cell K10 ?

 

Can you maybe post the Excel file?

Hey, I've edited to include in the original post. also put here for reference:
PowerQuery Forum Help file - Blended historic FX rate.xlsx
thanks

Please check this result. I believe your last number is incorrect.

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "zZTfT4MwEMf/lYYnTQb0x2DjEYfGTBeTzT0te6hQWTPWkrbM8N9b2IyaEY0PBp56l1y/97m73G02zoKqPTPOyHkQ8k2AWFvz9siEAQk1zDoz++RS1Y1ZKcVEWoOScgWu7iqRGi4FLdyZFEbR1FzbqIU8skMjYOqyEUiYThUvm0jrLa0cMBJUuhU//wPph3R8kJUwzna0cZANmK9iSIg1xj7yMURRI/G0tpy6pZ4vEne9SqwVZxk/53hWVOjWAYbuGajKJlUhNRe5tVBAwnHk4agrC4E/p0lYqVjKaas+21GVN3Useb4zQL6CtWanTyD7EmgjbgomMpaBe66NVDwFnzwuwhB7wfQSJ/DJL1X/D84Ye2F4iRMOqzuTYXVnOiycaFjDQvAPC7y0B4TqSp3uiGV5tC4Dj5y+8IKb+ts6u2QaES8MOnP2MxIYeUHHdUGon5mgCfSCSQcPHlh/TjgYDgMH+zjqAQcR5AUdC016646z3b4D",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [
        Column1 = _t,
        Column2 = _t,
        Column3 = _t,
        Column4 = _t,
        Column5 = _t,
        Column6 = _t,
        Column7 = _t,
        Column8 = _t,
        Column9 = _t
      ]
  ),
  #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
  #"Added Index" = Table.AddIndexColumn(#"Promoted Headers", "Index", 0, 1, Int64.Type),
  #"Changed Type" = Table.TransformColumnTypes(
    #"Added Index",
    {{"Event Date", type date}, {"Contract currency Amount", Currency.Type}}
  ),
  #"Added Custom" = Table.AddColumn(
    #"Changed Type",
    "Custom",
    each List.Accumulate(
      {0 .. [Index]},
      [a = 0, c = 0, v = 0, f = 0],
      (state, current) => [
        a = state[a] + #"Changed Type"[Contract currency Amount]{current},
        f =
          if #"Changed Type"[Rate to use]{current} = "Closing" then
            Table.SelectRows(
              Lookup_FX_Rates_table,
              each [Currency Pair]
                = #"Changed Type"[#"Currency pair (Functional-Contract)"]{current}
                and [Period] = Date.EndOfMonth(#"Changed Type"[Event Date]{current})
            )[Value]{0}
          else
            state[c] / state[a],
        v = #"Changed Type"[Contract currency Amount]{current} * f,
        c = state[c] + v
      ]
    )
  ),
  #"Expanded Custom" = Table.ExpandRecordColumn(
    #"Added Custom",
    "Custom",
    {"f", "v"},
    {"Relevant FX Rate", "Functional Currency Amount"}
  ),
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Expanded Custom",
    {{"Relevant FX Rate", type number}, {"Functional Currency Amount", Currency.Type}}
  )
in
  #"Changed Type1"

 

lbendlin_0-1736479958384.png

 

Hi Ibendlin,

Thanks very much for your response, I can see that works perfectly in that PBIX file and seems ideal (the difference on the last number is due to a slight change in the contract currency amount in your binary file from the data by $0.59).

 

Unfortunately when I try to utilise the same code in my model it is taking a signifcant amount of time to process the query. I have 4 years of journal CSV files that are being pulled into the query,  each around 100k rows and size 110,000KB. The query has been running for over 1hr30mins currently on my filtered journals to only those in the example and is loading a vast amount of data (current progress):

toBeTaughtIfPos_0-1736520311048.png

This is also only the first file. I think if trying to run at the scale I need it would likely take a signficant amount of processing time.

Do you have a recommendation for how I may be able to more efficiently perform this calculation, potentially outside of PBI and then directly load the data post calculation? Willing to chat with our IT dept to allow using other tools for this calc pre-PBI load if it is significantly more efficient.

 

If the above is surprising - then I'll go away, complete my planned rework of the model and try it again incase I've some embedded inefficencies in there that the planned rework can remove.

Please provide sample data that fully covers your issue.

Note1:  Power Query is inherently slow but there are ways to speed it up a bit by using buffers

Note2: As I mentioned this cannot be done in DAX which is a pity as DAX runs in memory and would be much faster

Note3:  If this works sufficiently fast in Excel then do it in Excel. This data looks like it is immutable so it's not really necessary to calculate over and over again.

Hi Ibendlin,

Thanks for the reply and apologies for the delay - I was pulled onto a few other things and had to put a pause on this.

Coming back to it now I have provided updated sample data which covers the issue with there being different leases in different currencies, and provided a comprehensive FX table.

PowerQuery Forum Help file - Blended historic FX rate 2.xlsx

 

In this data set you can see there are different leases which are denoted by the different "Known As" reference, and these have their own currency pairs depending on the market and contract. My FX table also has average rates within it, so have included them as it would need a different filter.

toBeTaughtIfPos_0-1738877725707.png

 

I tried to modify your code so that I could group the data by the individual leases based on the "Known as" and then run the function only on that subset of rows for each lease before expanding them back into the table (code below) but it didn't work as I get an error on the "records" column within the table.

"Expression.Error: We cannot convert the value 0 to type List.
Details:
Value=0
Type=[Type]"

 

#"Grouped Rows" = Table.Group(
        #"Reordered Columns", 
        {"Known As"}, 
        {
            {"All Data", each _, type table[
                Index = Int64.Type, 
                Market = text, 
                #"Event Date" = date, 
                Amount = number, 	
                Description = text,
                #"Reporting-Contract currency Pair" = text, 
                Category = text, 
                #"Movement type" = text, 
                #"Rate to use" = text
            ]}
        }
    ),
    
    #"Testing Function" = Table.AddColumn(#"Grouped Rows", "custom2", each Table.AddColumn([All Data], "records", each List.Accumulate(
                {0 .. List.Count([Index]) - 1},
                [a = 0.0, c = 0.0, v = 0.0, f = 0.0],
                (state, current) => [
                    a = state[a] + [Amount]{current},
                    f = if [#"Rate to use"]{current} = "Closing" then
                            Table.SelectRows(
                                Lookup_FX_Rates_table,
                                each [Currency Pair] = [#"Reporting-Contract currency Pair"]{current} and [Period] = Date.EndOfMonth([#"Event Date"]{current}) and [Currency Rate Type] = "Current"
                            )[Value]{0}
                        else state[c] / state[a],
                    v = [Amount]{current} * state[f],
                    c = state[c] + state[v]
                ]
            ))),
    #"Removed Columns" = Table.RemoveColumns(#"Testing Function",{"All Data"}),
    #"Expanded custom2" = Table.ExpandTableColumn(#"Removed Columns", "custom2", {"Index”, "Market", "Known As", "Event Date", "Amount", "Description", " Reporting-Contract currency Pair", "Category", "Rate to use", "records"}, {"Index”, "Market", "Known As", "Event Date", "Amount", "Description", " Reporting-Contract currency Pair", "Category", "Rate to use", "records"}),
// Expand the Custom column into separate fields
    #"Expanded Custom" = Table.ExpandRecordColumn(
        #"Expanded custom2",
        "records",
        {"f", "v"},
        {"Relevant FX Rate", "Functional Currency Amount"}
    ),

    #"Changed Type1" = Table.TransformColumnTypes(
        #"Expanded Custom",
        {{"Relevant FX Rate", type number}, {"Functional Currency Amount", Currency.Type}}
    )

 

I look forward to your response.

Thanks!

Hi @toBeTaughtIfPos, are you sure that your excel formula is correct?

 

I found different logic in your excel file.

  • For row 34 you use sum also for row 27
  • but for row 20 you sum from row 15

 

dufoq3_1-1738881721511.png

 

dufoq3_0-1738881668481.png


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi Dufoq3,

Great spot, you're absolutely right that was an error in the formula for that lease - I've updated the formula in that whole column so it uses SUMIFS on the lease number and values instead so that issue won't happen again. Thank you for spotting and flagging!

Hi @toBeTaughtIfPos, check this query, but don't you want to reset sumifs after each closing?

 

dufoq3_1-1739258984871.png

 

Result (same as in your excel file)

dufoq3_0-1739258888218.png

let
    Source = Excel.Workbook(File.Contents("C:\Users\dufoq3\Downloads\PowerQuery Forum Help file - Blended historic FX rate.xlsx"), null, true),
    FX_RatesTable = Table.PromoteHeaders(Source{[Item="Lookup_FX_Rates_table",Kind="Sheet"]}[Data]),
    FX_Rates = Record.Combine(Table.AddColumn(FX_RatesTable, "R", each Record.AddField([], [Currency Pair] & "_" & Date.ToText(Date.EndOfMonth([Period]), [Format="yyyyMMdd"]), [Value]), type record)[R]),
    Data = [ a = Table.PromoteHeaders(Source{[Item="Data_Journals",Kind="Sheet"]}[Data]),
    b = Table.SelectColumns(a, List.Select(Table.ColumnNames(a), each not Text.StartsWith(_, "Column"))),
    c = Table.SelectRows(b, each not List.Contains({null, ""}, [Event Date]))
  ][c],
    L = List.Buffer(Table.ToRows(Table.SelectColumns(Data,{"Event Date", "Currency pair (Functional-Contract)", "Rate to use", "Contract currency Amount"}))),
    Gen = List.Generate(
        ()=> [ x = 0, r = L{x}, w = {0, 0}, y = if r{2} = "Closing" then Record.FieldOrDefault(FX_Rates, r{1} & "_" & Date.ToText(Date.EndOfMonth(r{0}), [Format="yyyyMMdd"])) else null, z = y * r{3} ],
        each [x] < List.Count(L),
        each [ x = [x]+1, r = L{x},
               w = { [w]{0} + [z], [w]{1} + L{x-1}{3} },
               y = if r{2} = "Closing" then Record.FieldOrDefault(FX_Rates, r{1} & "_" & Date.ToText(Date.EndOfMonth(r{0}), [Format="yyyyMMdd"])) else w{0} / w{1},
               z = y * r{3} ],
        each {[y], [z]}
),
    Merged = Table.FromColumns(Table.ToColumns(Data) & {List.Transform(Gen, each _{0}), List.Transform(Gen, each _{1})}, Value.Type(Table.FirstN(Data,0) & #table(type table[Relevant FX Rate_Gen=number, Functional Currency Amount_Gen=number], {})))
in
    Merged

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors