select Opportunity__r.Country_of_Ownership__c,CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c)Months,CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)years,
sum(Transaction_Allocation__c.Amount__c) amount,Opportunity__r.CurrencyIsoCode
from Transaction_Allocation__c
where
(Transaction_Allocation__c.Close_Date__c > 2022-03-31 AND Transaction_Allocation__c.Close_Date__c < NEXT_N_DAYS:1)
AND
(Transaction_Allocation__c.Stage__c IN ('Posted','Refunded','Failed','Refund','Reversal')
AND Transaction_Allocation__c.GL_Code__c IN ('50030','50020','50050','50060','50200','51020','51040','50110','50120','50130','50240','51030','51060','50170','50171','51050'))
Group by
Opportunity__r.Country_of_Ownership__c, CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c),CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),Opportunity__r.CurrencyIsoCode