Nim Sadeh
10/12/2022, 8:00 PMselect averagerate from consolidatedexchangerate where fromcurrency = <sub_currency> and postingperiod = <posting_period>
that is, compute the average rate for a subsidiary for a posting period, not using the above table. Right now I have:
select sum(abs(tal.amount) * cr.exchangerate) / sum(abs(tal.amount))
from transactionaccountingline tal
inner join transaction t on t.id = tal.transaction
inner join transactionline tl on tl.id = tal.transactionline and tl.transaction = tal.transaction
inner join currencyrate cr on cr.effectivedate = t.trandate and cr.transactioncurrency = t.currency
inner join account a on a.id = tal.account
where t.postingperiod = '<posting_period>'
and t.currency = '<subsidiary_currency>'
and tl.subsidiary = '<subsidiary>'
and cr.basecurrency = '<parent_basecurrency>'
and a.generalrate = 'AVERAGE'
I am close right up to 3 significant figures, but I think I should be exactly right. I must not be getting the right subset of transaction accounting lines. What am I doing wrong here.Nim Sadeh
10/12/2022, 8:00 PMMarc Reicher
10/13/2022, 9:16 PMconsolidatedexchangerate
table?Nim Sadeh
10/13/2022, 9:18 PMMarc Reicher
10/13/2022, 9:21 PMNim Sadeh
10/13/2022, 9:22 PMMarc Reicher
10/13/2022, 9:24 PMNim Sadeh
10/13/2022, 9:26 PMNim Sadeh
10/13/2022, 9:28 PMMarc Reicher
10/13/2022, 9:28 PMNim Sadeh
10/13/2022, 9:33 PMMarc Reicher
10/13/2022, 9:34 PMMarc Reicher
10/13/2022, 9:41 PMinner join currencyrate cr on cr.effectivedate = t.trandate and cr.transactioncurrency = t.currency
and this in you WHERE clause:
and cr.basecurrency = '<parent_basecurrency>'
Could this all be baked into the FROM clause as
inner join currencyrate cr on cr.effectivedate = t.trandate and cr.transactioncurrency = t.currency and cr.basecurrency = '<parent_basecurrency>'
Marc Reicher
10/13/2022, 9:41 PMNim Sadeh
10/13/2022, 9:43 PMMarc Reicher
10/13/2022, 9:44 PMMarc Reicher
10/13/2022, 9:48 PMNim Sadeh
10/13/2022, 9:48 PMand t.postingbook = '1'
in earlier versions of this query and the results didn’t changeJon Kears
10/14/2022, 12:47 AMMarc Reicher
10/14/2022, 12:51 AMJon Kears
10/14/2022, 1:00 AMJon Kears
10/14/2022, 1:00 AMMarc Reicher
10/14/2022, 1:14 AMJon Kears
10/14/2022, 1:20 AMMarc Reicher
10/14/2022, 1:45 AMNim Sadeh
10/14/2022, 4:13 AMNim Sadeh
10/14/2022, 4:13 AMNim Sadeh
10/14/2022, 4:17 AMselect sum(abs(tal.amount) * cr.exchangerate) / sum(abs(tal.amount))
from transactionaccountingline tal
inner join transaction t on t.id = tal.transaction
left join currencyrate cr on cr.effectivedate = t.trandate and cr.transactioncurrency = t.currency and cr.basecurrency = '<parent_basecurrency>'
left join account a on a.id = tal.account
where t.postingperiod = '<posting_period>'
and t.subsidiary = '<subsidiary>'
and a.generalrate = 'AVERAGE'
Nim Sadeh
10/14/2022, 4:19 AMNim Sadeh
10/14/2022, 4:24 AMJon Kears
10/14/2022, 4:46 AMon subsidiary.basecurrency = cr.transactioncurrency AND <parent_basecurrency> = cr.basecurrency AND t.trandate = cr.creffectivedate
Now this might or might not matter depending on the nature of transactions you have in this subsidiary. I suspect Netsuite is doing something with rounding, and something with null values, as if (for example) you have no transactions at all then it forces a consolidated exchange rate of the last day of the period.Nim Sadeh
10/14/2022, 2:36 PMNim Sadeh
10/14/2022, 2:42 PMMarc Reicher
10/14/2022, 4:46 PMselect averagerate from consolidatedexchangerate where fromcurrency = <sub_currency> and postingperiod = <posting_period>
I think we're really talking about replicating the result from this though:
select averagerate from consolidatedexchangerate where fromsubsidiary = <subsidiary> and tosubsidiary = <parent> and postingperiod = <posting_period>
In theory, this could get you the same record, but just want to confirmNim Sadeh
10/14/2022, 6:15 PM