How to sum the field based on every year!!! (1 Viewer)

balaryan

Registered User.
Local time
Today, 19:23
Joined
Jul 1, 2015
Messages
12
Hi All,

Good day. I am new born to VBA and tried writing a SQL query to produce the list of details in year wise DESCENDING order for the input - Agent ID.

In addition to that I need to get the sum of amount fields year wise in the report. How to achieve it???.

Please find the attached report for better clarification.

First three column in the attachment is the outcome of the below listed query. Whereas the fourth column is the expected result which needs to be included..

Code:
SELECT CessioneCredito.Data_Movimento, CessioneCredito.Anno,  CessioneCredito.Importo FROM CessioneCredito  
WHERE (((CessioneCredito.ID_Agente)=[Reports]![R_StoricoCessCredAg]![ID_Agente]))
ORDER BY CessioneCredito.Data_Movimento DESC;

How to alter the code in order to provide the SUM of Importo field every year.???

Thanks in advance. Appreciate your time.
 

Attachments

  • Total sum in the report.jpg
    Total sum in the report.jpg
    53.3 KB · Views: 80

namliam

The Mailman - AWF VIP
Local time
Today, 15:53
Joined
Aug 11, 2003
Messages
11,695
Is this what you are looking for?

Code:
SELECT CessioneCredito.Anno,  sum(CessioneCredito.Importo) FROM CessioneCredito  
WHERE (((CessioneCredito.ID_Agente)=[Reports]![R_StoricoCessCredAg]![ID_Agente]))
Group by CessioneCredito.Anno
order by CessioneCredito.Anno;
 

balaryan

Registered User.
Local time
Today, 19:23
Joined
Jul 1, 2015
Messages
12
Hi Namliam,

I need a report with four columns as per the attachment,

like

Data_Movimento Anno Sum Total

as shown in the attachment.

But the total should be displayed to minimum of Data_movimento field for every year.

So any idea how to achieve it in SQL query?
 

namliam

The Mailman - AWF VIP
Local time
Today, 15:53
Joined
Aug 11, 2003
Messages
11,695
Perhaps something along these lines?
Code:
SELECT CessioneCredito.Data_Movimento, CessioneCredito.Anno,  CessioneCredito.Importo, null as total 
FROM CessioneCredito  
WHERE (((CessioneCredito.ID_Agente)=[Reports]![R_StoricoCessCredAg]![ID_Agente]))
Union
SELECT null                          , CessioneCredito.Anno,  null                   , sum(CessioneCredito.Importo) 
FROM CessioneCredito  
WHERE (((CessioneCredito.ID_Agente)=[Reports]![R_StoricoCessCredAg]![ID_Agente]))
Group by CessioneCredito.Anno
order by CessioneCredito.Anno;
Otherwize try a report?
 

Users who are viewing this thread

Top Bottom