Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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)
Market | Known As | Event Date | Category | Currency pair (Functional-Contract) | Movement type | Description | Rate to use | Contract currency Amount | Relevant FX Rate | Functional Currency Amount |
1 | JSA033 | 4/1/2019 | ROU Asset | JMD-USD | Addition | Transition take up | Closing | 153649.29 | 134.354427 | 20643462.32 |
1 | JSA033 | 4/30/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1202.58 | 134.354427 | -161571.9468 |
1 | JSA033 | 5/31/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1242.66 | 134.354427 | -166956.8723 |
1 | JSA033 | 6/30/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1202.58 | 134.354427 | -161571.9468 |
1 | JSA033 | 7/31/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1242.66 | 134.354427 | -166956.8723 |
1 | JSA033 | 8/31/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1242.66 | 134.354427 | -166956.8723 |
1 | JSA033 | 9/30/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1202.58 | 134.354427 | -161571.9468 |
1 | JSA033 | 10/1/2019 | ROU Asset | JMD-USD | Addition | Remeasurement of Lease Liability | Closing | -3893.65 | 135.153399 | -526240.032 |
1 | JSA033 | 10/31/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1209.59 | 134.3325837 | -162487.3499 |
1 | JSA033 | 11/30/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1170.57 | 134.3325837 | -157245.6925 |
1 | JSA033 | 12/31/2019 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1209.59 | 134.3325837 | -162487.3499 |
1 | JSA033 | 1/31/2020 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1209.59 | 134.3325837 | -162487.3499 |
1 | JSA033 | 2/29/2020 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1131.56 | 134.3325837 | -152005.3784 |
1 | JSA033 | 3/31/2020 | ROU Asset | JMD-USD | Depreciation Charge | Right of Use Asset depreciation | Blended Historic Closing | -1209.59 | 134.3325837 | -162487.3499 |
and Table2: Lookup_FX_Rates_table
Currency Rate Type | Currency Pair | Period | Value |
Current | JMD-USD | 4/30/2019 | 134.354427 |
Current | JMD-USD | 5/31/2019 | 136.351241 |
Current | JMD-USD | 6/30/2019 | 134.048257 |
Current | JMD-USD | 7/31/2019 | 127.991809 |
Current | JMD-USD | 8/31/2019 | 126.871352 |
Current | JMD-USD | 9/30/2019 | 126.807 |
Current | JMD-USD | 10/31/2019 | 135.153399 |
Current | JMD-USD | 11/30/2019 | 128.205128 |
Current | JMD-USD | 12/31/2019 | 125.015627 |
Current | JMD-USD | 1/31/2020 | 133.74348 |
Current | JMD-USD | 2/29/2020 | 132.766861 |
Current | JMD-USD | 3/31/2020 | 130.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):
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
Solved! Go to 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!
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.
@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!
@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 @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"
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.
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"
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):
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.
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.
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?
Result (same as in your excel file)
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
8 | |
7 |