Hello All;
Here is my query where i am joining two tables and want to calculate sum.
Can Somebody plz check and tell me how i can calculate sum , and whats wrong with my query....
Here is the query
while select AccountingCurrencyAmount,GeneralJournalEntry from generalJournalAccountEntry
join generalJournalEntry where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
&& generalJournalEntry.AccountingDate >= mkDate(1,1,2019) && generalJournalEntry.AccountingDate <= mkDate(28,2,2019)
&& generalJournalAccountEntry.LedgerDimension ==valueView2.ValueCombinationRecId
{
TotalValues += sum(generalJournalAccountEntry.AccountingCurrencyAmount);
info(strfmt('Sum %1 ledger dimension : %2',generalJournalAccountEntry.AccountingCurrencyAmount,TotalValues));
}
*This post is locked for comments
You have a loop with select inside, so with minor changes you will get one value for all accounts and projects:
while select valueView where valueView.DisplayValue == projId && valueView.DimensionAttribute == DimAttrProject.RecId { select valueView2 where valueView2.ValueCombinationRecId == valueView.ValueCombinationRecId && valueView2.DimensionAttribute == DimAttrMainAccount.RecId && valueView2.DisplayValue == cscMainaccount; if (valueView2.RecId) { select sum(AccountingCurrencyAmount) from generalJournalAccountEntry where generalJournalAccountEntry.LedgerDimension == valueView2.ValueCombinationRecId join generalJournalEntry order by AccountingDate Asc where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry && generalJournalEntry.AccountingDate >= _startDate && generalJournalEntry.AccountingDate <= _endDate; totalValues += generalJournalAccountEntry.AccountingCurrencyAmount;
} }
info(strFmt("%1",TotalValues));
I highlighted changes I made
Hi ievgen;
here is my complete code , What i want is to get total credit amount with the combination of Project and Main account.
But the problem is i am getting a single value, job is returning all the records but my requirement is to sum all of them
and display as a single record.... Can you check what's wrong with my code
static void Job32(Args _args)
{
GeneralJournalAccountEntry generalJournalAccountEntry;
GeneralJournalEntry generalJournalEntry;
DimensionAttributeLevelValueView valueView,valueview2;
DimensionAttributeValueCombination combination;
ProjId projId;
AccountingDate _startDate = mkDate(1,1,2019);
AccountingDate _endDate = mkDate(25,2,2019);
MainAccountNum cscMainaccount;
real TotalValues;
DimensionAttribute DimAttrProject = DimensionAttribute::findByName('Project');
DimensionAttribute DimAttrMainAccount = DimensionAttribute::findByName('MainAccount');
projId = "OSM-06-01-01-0073";
cscMainaccount = "33510002";
TotalValues = 0.0;
while select valueView
where valueView.DisplayValue == projId
&& valueView.DimensionAttribute == DimAttrProject.RecId
{
select valueView2
where valueView2.ValueCombinationRecId == valueView.ValueCombinationRecId
&& valueView2.DimensionAttribute == DimAttrMainAccount.RecId
&& valueView2.DisplayValue == cscMainaccount;
if(valueView2.RecId)
{
select sum(AccountingCurrencyAmount) from generalJournalAccountEntry
where generalJournalAccountEntry.LedgerDimension == valueView2.ValueCombinationRecId
join generalJournalEntry order by AccountingDate Asc
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
&& generalJournalEntry.AccountingDate >= _startDate
&& generalJournalEntry.AccountingDate <= _endDate;
TotalValues = generalJournalAccountEntry.AccountingCurrencyAmount;
info(strFmt("%1",TotalValues));
}
}
}
Does it even compile ? You can either use sum in select statement:
select sum(AccountingCurrencyAmount) from generalJournalAccountEntry join generalJournalEntry where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry && generalJournalEntry.AccountingDate >= mkDate(1,1,2019) && generalJournalEntry.AccountingDate <= mkDate(28,2,2019) && generalJournalAccountEntry.LedgerDimension == valueView2.ValueCombinationRecId; TotalValues = generalJournalAccountEntry.AccountingCurrencyAmount; info(strfmt('Sum %1 ledger dimension : %2',generalJournalAccountEntry.AccountingCurrencyAmount,TotalValues));
or add them manually:
while select AccountingCurrencyAmount from generalJournalAccountEntry join generalJournalEntry where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry && generalJournalEntry.AccountingDate >= mkDate(1,1,2019) && generalJournalEntry.AccountingDate <= mkDate(28,2,2019) && generalJournalAccountEntry.LedgerDimension == valueView2.ValueCombinationRecId { TotalValues += generalJournalAccountEntry.AccountingCurrencyAmount; info(strfmt('Sum %1 ledger dimension : %2',generalJournalAccountEntry.AccountingCurrencyAmount,TotalValues)); }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156