Snippets Collections
with events as (
  select
  device.web_info.hostname AS Hostname,
      -- traffic_source.name (dimension | name of the marketing campaign that first acquired the user)
 (select value.int_value from unnest(event_params) where key = 'ga_session_id') as session_id,
    traffic_source.medium AS First_medium,
    -- traffic_source.source (dimension | name of the network that first acquired the user)
    traffic_source.source as First_Source,
    device.category as device_category,
    user_pseudo_id,
    event_name,
    event_timestamp,
    traffic_source.name AS First_campaign,
    max((select value.string_value from unnest(event_params) where key = 'session_engaged')) as session_engaged,
    max((select value.int_value from unnest(event_params) where key = 'video_duration')) as Video_views,
    regexp_replace(
  regexp_replace(
    (
      select
        p.value.string_value
      from
        unnest(event_params) as p
      where
        p.key = 'page_location'
    ),
    r'^https?://[^/]+',
    ''
  ),
  r'[\?].*',
  ''
) as page_path,
regexp_replace((select value.string_value from unnest(event_params) where key = 'page_location'), r'\?.*', '') as page_location,
(select value.string_value from unnest(event_params) where key = 'page_title') as page_title,
event_date as date

FROM 
`bigquery-341716.analytics_278788286.events_*`

where

 _table_suffix between format_date('%Y%m%d',date_sub(current_date(), interval 2 day))
    and format_date('%Y%m%d',date_sub(current_date(), interval 2 day))
    
    and user_pseudo_id IS NOT null

group by
Hostname,
session_id,
First_medium,
First_Source,
First_campaign,
device_category,
user_pseudo_id,
event_name,
event_timestamp,
page_path,
page_location,
page_title,
date
    )
 


  select
  date,
  Hostname,
  device_category,
  page_path,
  page_location,
  page_title,
  First_campaign,
  countif(event_name = 'page_view') as PageView,
  countif(event_name = 'action_form_submitted') as action_form_submitted,   
  countif(event_name = 'contact_form_submitted') as contact_form_submitted,
 countif(event_name = 'engaged_3_pageviews') as engaged_3_pageviews,
 countif(event_name = 'file_download') as file_download,
 --COUNTIF(Video_views  >1)  as video_progress,
--countif(event_name = 'video_progress') as test,
 count(distinct case when event_name = 'video_progress' then concat(user_pseudo_id,session_id) end) as video_progress,
count(distinct case when session_engaged = '1' then concat(user_pseudo_id,session_id) end) as engaged_sessions,

  -- definitions of the channel grouping based on the source / medium of every session
    case
        when First_Source is null and (First_medium = '(not set)' or First_medium is null) then 'Direct'
        when First_medium = 'organic' then 'Organic Search'
        when regexp_contains(First_medium, r'^(social|social-network|social-media|sm|social network|social media)$') then 'Social'
        when First_medium = 'email' then 'Email'
        when First_medium = 'affiliate' then 'Affiliates'
        when First_medium = 'referral' then 'Referral'
        when regexp_contains(First_medium, r'^(cpc|ppc|paidsearch)$') then 'Lead Gen'
        when regexp_contains(First_medium, r' ^(cpv|cpa|cpp|content-text)$') then 'Other Advertising'
        when regexp_contains(First_medium, r'^(display|cpm|banner)$') then 'Display'
        else '(Other)' end as session_default_channel_grouping,

  from
  events

  group by
  Hostname,
  device_category,
  session_default_channel_grouping,
  page_path,
  page_location,
  page_title,
  First_campaign,
  date
with events as (
  select
  device.web_info.hostname AS Hostname,
      -- traffic_source.name (dimension | name of the marketing campaign that first acquired the user)
    traffic_source.name AS First_campaign,
    -- traffic_source.medium (dimension | name of the medium (paid search, organic search, email, etc.) that first acquired the user)
    traffic_source.medium AS First_medium,
    -- traffic_source.source (dimension | name of the network that first acquired the user)
    traffic_source.source as First_Source,
    device.category as device_category,
    -- device.mobile_brand_name (dimension | the device brand name)
    device.mobile_brand_name as brand,
--page data

regexp_replace((select value.string_value from unnest(event_params) where key = 'page_location'), r'\?.*', '') as page_location,
(select value.string_value from unnest(event_params) where key = 'page_title') as page_title,

  user_pseudo_id,
   
    concat(user_pseudo_id,(select value.int_value from unnest(event_params) where key = 'ga_session_id')) as unique_session_id,

     -- (case when(
       -- select
        --  value.string_value
        --from
          --unnest(event_params)
        --where
         -- key = 'session_engaged' AND event_name = 'page_view'
      --) ="1" then 1 else 0 end) as engaged_sessions_id,

(case when (select value.string_value from unnest(event_params) where key = 'session_engaged') = '1' then concat(user_pseudo_id,(select value.int_value from unnest(event_params) where key = 'ga_session_id')) end) as engaged_sessions_id,    
event_name,
    event_timestamp,
    regexp_replace(regexp_replace((select p.value.string_value from unnest(event_params) as p where p.key = 'page_location'), r'^https?://[^/]+',''), r'[\?].*','') as page_path,
event_date as date

FROM 
`bigquery-341716.analytics_278788286.events_*`

where

  _table_suffix between format_date('%Y%m%d',date_sub(current_date(), interval 2 day))
    and format_date('%Y%m%d',date_sub(current_date(), interval 2 day))
    AND user_pseudo_id IS NOT null)
 ,

flow as
(select
  unique_session_id,
  user_pseudo_id,
  engaged_sessions_id,
  page_location,
  page_title,
  device_category,
  brand,
  Hostname,
  event_name,
  page_path,
  date,
  event_timestamp,
    First_Source,
     First_medium,
     First_campaign,
  -- look for the previous page_path
  if(
    event_name = 'page_view',
    coalesce(
      last_value(
        if(event_name = 'page_view', page_path, null) ignore nulls
      ) over(
        partition by unique_session_id
        order by
          event_timestamp asc rows between unbounded preceding
          and 1 preceding
      ),
      '(entrance)'
    ),
    null
  ) as previous_page,
  -- look for the next page_path
  if(
    event_name = 'page_view',
    coalesce(
      first_value(
        if(event_name = 'page_view', page_path, null) ignore nulls
      ) over(
        partition by unique_session_id
        order by
          event_timestamp asc rows between 1 following
          and unbounded following
      ),
      '(exit)'
    ),
    null
  ) as next_page
from
  events
  where
 event_name = 'page_view'
  )


  select
  date,
  Hostname,
  device_category,
  flow.page_path,
  page_location,
  page_title,
  First_campaign,


  -- definitions of the channel grouping based on the source / medium of every session
    case
        when First_Source is null and (First_medium = '(not set)' or First_medium is null) then 'Direct'
        when First_medium = 'organic' then 'Organic Search'
        when regexp_contains(First_medium, r'^(social|social-network|social-media|sm|social network|social media)$') then 'Social'
        when First_medium = 'email' then 'Email'
        when First_medium = 'affiliate' then 'Affiliates'
        when First_medium = 'referral' then 'Referral'
        when regexp_contains(First_medium, r'^(cpc|ppc|paidsearch)$') then 'Lead Gen'
        when regexp_contains(First_medium, r' ^(cpv|cpa|cpp|content-text)$') then 'Other Advertising'
        when regexp_contains(First_medium, r'^(display|cpm|banner)$') then 'Display'
        else '(Other)' end as session_default_channel_grouping,
  --groups page types
 CASE
    WHEN next_page like '%petition/1%' THEN 'petition'
    WHEN next_page like '%petition/2%' THEN 'petition'
    WHEN next_page like '%donate/1%' THEN 'donate'
    WHEN next_page like '%donate/2%' THEN 'donate'
    WHEN next_page like '%wspieram/1%' THEN 'donate'
    WHEN next_page like '%wspieram/2%' THEN 'donate'
    WHEN next_page like '%doneren/1%' THEN 'donate'
    WHEN next_page like '%doneren/2%' THEN 'donate'
    WHEN next_page like '%donazioni/1%' THEN 'donate'
    WHEN next_page like '%donazioni/2%' THEN 'donate'
    WHEN next_page like '%don/1%' THEN 'donate'
    WHEN next_page like '%don/2%' THEN 'donate'
    WHEN next_page like '%daruj/1%' THEN 'donate'
    WHEN next_page like '%daruj/2%' THEN 'donate'
    WHEN next_page like '%donar/1%' THEN 'donate'
    WHEN next_page like '%donar/2%' THEN 'donate'
    WHEN next_page like '%action/1%' THEN 'action'
    WHEN next_page like '%action/2%' THEN 'action'
    WHEN next_page like '%actie/1%' THEN 'action'
    WHEN next_page like '%actie/2%' THEN 'action'
    WHEN next_page like '%akcje/1%' THEN 'action'
    WHEN next_page like '%akcje/2%' THEN 'action'
    WHEN next_page like '%accion/1%' THEN 'action'
    WHEN next_page like '%accion/2%' THEN 'action'
    WHEN next_page like '%akce/1%' THEN 'action'
    WHEN next_page like '%akce/2%' THEN 'action'
    WHEN next_page like '%subscribe/1%' THEN 'subscribe'
    WHEN next_page like '%subscribe/2%' THEN 'subscribe'
    WHEN next_page like '%data/2%' THEN 'data'
    WHEN next_page like '%data/1%' THEN 'data'
    WHEN next_page like '(exit)' THEN 'exit'


    ELSE 'Website'
END AS NextPageType,

--add measures
  
  COUNT (DISTINCT user_pseudo_id) AS Users,
  COUNT (DISTINCT unique_session_id) AS sessions,
  COUNT (DISTINCT engaged_sessions_id) AS engaged_sessions,
  COUNT(CASE WHEN previous_page = '(entrance)' THEN unique_session_id ELSE NULL END) AS Entrance,
  COUNT(CASE WHEN next_page = '(exit)' THEN unique_session_id ELSE NULL END) AS Exit,
  next_page

  from
  flow
  group by
  date,
  Hostname,
  page_location,
  page_title,
  First_campaign,
  device_category,
  page_path,
  session_default_channel_grouping,
  NextPageType,
  next_page

with prep as 
(select  
--key session data
user_pseudo_id,
event_date as date,
device.web_info.hostname AS Hostname,
device.category as device_category,
(select value.string_value from unnest(event_params) where key = 'ga_session_id') as ga_session_id,
concat(user_pseudo_id,(select value.int_value from unnest(event_params) where key = 'ga_session_id')) as sessions,
(case when event_name = "first_visit" then user_pseudo_id end) as new_user,

--page data
regexp_replace(regexp_replace((select p.value.string_value from unnest(event_params) as p where p.key = 'page_location'),r'^https?://[^/]+',''),r'[\?].*','') as page_path,
regexp_replace((select value.string_value from unnest(event_params) where key = 'page_location'), r'\?.*', '') as page_location,
 (select value.string_value from unnest(event_params) where key = 'page_title') as page_title,

--FIrst traffic data
traffic_source.name AS First_Campaign,
traffic_source.medium AS FIRST_medium,
traffic_source.source AS FIRST_source,

--Engagement metrics
max((select value.string_value from unnest(event_params) where key = 'session_engaged')) as session_engaged,
sum((select value.int_value from unnest(event_params) where key = 'engagement_time_msec'))/1000 as engagement_time_seconds,
max((select value.int_value from unnest(event_params) where key = 'engagement_time_msec')) as engagement_time_msec,
max((select value.int_value from unnest(event_params) where key = 'engagement_time_msec'AND user_pseudo_id is not null)) as USER_engagement_time_msec,
max((select value.string_value from unnest(event_params) where key = 'variant_id')) as variant_id,
max((select value.string_value from unnest(event_params) where key = 'experiment_id')) as experiment_id,
max((select item_name from unnest(items) )) as itemName,

  count(distinct case when event_name = "page_view" then 
      concat(user_pseudo_id,event_timestamp) end) as page_views
   
from  `bigquery-341716.analytics_278788286.events_*`
WHERE _table_suffix between format_date('%Y%m%d',date_sub(current_date(), interval 2 day))
    and format_date('%Y%m%d',date_sub(current_date(), interval 2 day))

group by
user_pseudo_id,
page_path,
page_location,
page_title,
date,
ga_session_id,
sessions,
new_user,
First_Campaign,
FIRST_medium,
FIRST_source,
Hostname,
device_category)

select 
Hostname,
date,
First_medium as medium,
FIRST_source as source,
First_Campaign as Campaign,
itemName as Campaign_code,
page_path,
page_location,
page_title,

case
        when First_Campaign is null and (First_medium = '(not set)' or First_medium is null) then 'Direct'
        when First_medium = '(none)' then 'Direct'
        when First_medium = 'null' then 'Direct'
        when First_medium = 'organic' then 'Organic Search'
        when regexp_contains(First_medium, r'^(facebook|twitter|youtube|social|social-network|social-media|sm|social network|social media)$') then 'Social'
        when regexp_contains(First_medium, r'^(share|shared)$') then 'Shared'
        when regexp_contains(First_medium, r'^(email|emai|email-|ciwf)$') then 'Email'
        when First_medium = 'affiliate' then 'Affiliates'
        when First_medium = 'referral' then 'Referral'
        when First_medium = 'QR-code' then 'QR-code'
        when regexp_contains(First_medium, r'^(cpc|ppc|paidsearch)$') then 'Lead Gen'
        when regexp_contains(First_medium, r' ^(cpv|cpa|cpp|content-text)$') then 'Other Advertising'
        when regexp_contains(First_medium, r'^(display|cpm|banner)$') then 'Display'
        else '(Other)' end as session_default_medium_grouping,

 count(distinct sessions) as sessions,
  --count(distinct concat(user_pseudo_id,ga_session_id)) as sessions, 
  count(distinct case when session_engaged = '1' then concat(user_pseudo_id)END) as Engaged_Sessions,
  COUNT (DISTINCT user_pseudo_id) AS Users,
  COUNT (DISTINCT new_user) AS near_Users,
  sum(page_views) as page_view,
  --(sum(engagement_time_seconds),count(distinct case when session_engaged = '1' then sessions end)) as engagement_time,
  (safe_divide(sum(USER_engagement_time_msec),count(distinct case when session_engaged = '1' then sessions end)))/1000 as USER_engagement_time

from prep
group by
Hostname,
Campaign,
itemName,
date,
First_medium,
FIRST_source,
session_default_medium_grouping,
device_category,
page_path,
page_location,
page_title
select  
user_pseudo_id,
regexp_replace(regexp_replace((select p.value.string_value from unnest(event_params) as p where p.key = 'page_location'),r'^https?://[^/]+',''),r'[\?].*','') as page_path,
regexp_replace((select value.string_value from unnest(event_params) where key = 'page_location'), r'\?.*', '') as page_location,
 (select value.string_value from unnest(event_params) where key = 'page_title') as page_title,
event_date as date,
(select value.string_value from unnest(event_params) where key = 'ga_session_id') as ga_session_id,
concat(user_pseudo_id,(select value.int_value from unnest(event_params) where key = 'ga_session_id')) as sessions,
traffic_source.name AS First_Campaign,
traffic_source.medium AS FIRST_medium,
traffic_source.source AS FIRST_source,
device.web_info.hostname AS Hostname,
device.category as device_category,

max((select value.string_value from unnest(event_params) where key = 'session_engaged')) as session_engaged,
sum((select value.int_value from unnest(event_params) where key = 'engagement_time_msec'))/1000 as engagement_time_seconds,
max((select value.int_value from unnest(event_params) where key = 'engagement_time_msec')) as engagement_time_msec,
max((select value.string_value from unnest(event_params) where key = 'variant_id')) as variant_id,
max((select value.string_value from unnest(event_params) where key = 'experiment_id')) as experiment_id,
max((select item_name from unnest(items) )) as itemName,
   
from  `bigquery-341716.analytics_278788286.events_*`
WHERE _table_suffix between format_date('%Y%m%d',date_sub(current_date(), interval 2 day))
    and format_date('%Y%m%d',date_sub(current_date(), interval 2 day))

group by
user_pseudo_id,
page_path,
page_location,
page_title,
date,
ga_session_id,
sessions,
First_Campaign,
FIRST_medium,
FIRST_source,
Hostname,
device_category
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, sum(Transaction_Allocation__c.Amount__c) amount,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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

Opportunity__r.CiWF_Payment_Method__c IN ('Standing Order')
AND
(Transaction_Allocation__c.Stage__c IN ('Posted','Refunded','Failed','Refund','Reversal')
AND
((
Opportunity__r.RecordTypeId IN ('012w00000006jGy')
 AND
Opportunity__r.Date_Recurring_Donation_Established__c  > 2022-03-31
 
)
OR
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = False))
 
AND
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')
AND
Opportunity__r.Contact_Earliest_Record_Date__c<= 2022-03-31)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','012w00000006jGo')
AND Opportunity__r.Campaign_Type__c IN ('Appeal-Facebook') 
AND Transaction_Allocation__c.GL_Code__c IN ('50050') )
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
Donor_Contact__r.Country_of_Ownership__c, 
COUNT_DISTINCT(Donor_Contact__r.Id) The_Count  
 
from Opportunity

where
Donor_Contact__r.npo02__LastCloseDate__c< LAST_n_MONTHS:24
AND
RecordTypeId IN ('0122X000000ie1A','012w00000006jGy','012w00000006jGe','012w00000006jGo','012w0000000MQol','012w0000000MQuZ','012w0000000hbgn')
and
Amount>0
AND
StageName IN ('Posted','Refunded','Failed','Refund','Reversal') 
AND
Donor_Contact__r.Donor_Status__c IN ('Active','Lapsed','Laspsing') 
AND 
Donor_Contact__r.CIWF_Digital_Test_Account__c = FALSE

Group by 
Donor_Contact__r.Country_of_Ownership__c
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,
COUNT_DISTINCT(Opportunity__r.Id) The_Count

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','50090')) 
AND
 Opportunity__r.RecordTypeId IN ('012w00000006jGy','0122X000000ie1A')
 AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')

Group by Opportunity__r.Country_of_Ownership__c,CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,    Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 ('50020','50050','50140') 
AND  Opportunity__r.CiWF_Payment_Method__c IN ('Agency'))
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
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,
COUNT_DISTINCT(Opportunity__r.Id) The_Count,
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','50090')
AND Opportunity__r.Contact_Earliest_Record_Date__c> 2022-03-31
AND
((Opportunity__r.RecordTypeId IN ('012w00000006jGy') 
AND Opportunity__r.Date_Recurring_Donation_Established__c > 2022-03-31)
OR
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = False))

Group by Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
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 Opportunity__r.RecordTypeId IN ('012w00000006jGy','0122X000000ie1A')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
  
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w00000006jGy','0122X000000ie1A')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50030','50090','50060')) 
  
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, 
sum(Transaction_Allocation__c.Amount__c) amount,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50020','50050','50060','50200') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)
AND
Transaction_Allocation__c.Amount__c < 500 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count,
sum(Transaction_Allocation__c.Amount__c) amount,      
  Opportunity__r.CiWF_Payment_Method__c, 
  Opportunity__r.Country_of_Ownership__c, 
  Opportunity__r.CurrencyIsoCode, 
  CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
AND
Opportunity__r.CampaignId = '7014J000000MQ63QAG'
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count,
sum(Transaction_Allocation__c.Amount__c) amount,     
Opportunity__r.CiWF_Payment_Method__c, 
  Opportunity__r.Country_of_Ownership__c, 
  Opportunity__r.CurrencyIsoCode, 
  CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,
  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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.Amount__c <0
AND 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
AND
Opportunity__r.CampaignId = '7014J000000MQ63QAG'
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,    Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
AND
Opportunity__r.CampaignId = '7014J000000MQ63QAG'
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,    Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','0122X000000ie1F','012w00000006jGe','012w00000006jGo','012w00000006jGy','0122X000000ie1A')
                                    
 
AND Transaction_Allocation__c.GL_Code__c IN ('50110') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,    Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
from Transaction_Allocation__c
where 
(
  Transaction_Allocation__c.Stage__c IN ('Posted','Refunded','Failed','Refund','Reversal')
 
AND
  
     (Transaction_Allocation__c.Close_Date__c  > 2022-03-31 AND                Transaction_Allocation__c.Close_Date__c  < NEXT_N_DAYS:1) 
 
  AND
   
 Opportunity__r.RecordTypeId IN ('012w00000006jGo')
 
      
AND
Is_this_First_Donation_from_Oppty__c = False
 
AND
Transaction_Allocation__c.GL_Code__c IN ('51060', '50130')
 
 )

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,    Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','0122X000000ie1F','012w00000006jGe','012w00000006jGo','012w00000006jGy','0122X000000ie1A')
                                    
 
AND Transaction_Allocation__c.GL_Code__c IN ('51020') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, 
  COUNT_DISTINCT(Opportunity__r.Id) The_Count,    
  Opportunity__r.CiWF_Payment_Method__c, 
  Opportunity__r.Country_of_Ownership__c, 
  Opportunity__r.CurrencyIsoCode, 
  CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
from Transaction_Allocation__c
 where 
(
  Transaction_Allocation__c.Stage__c IN ('Posted','Refunded','Failed','Refund','Reversal')
AND
     (Transaction_Allocation__c.Close_Date__c  > 2022-03-31 AND                Transaction_Allocation__c.Close_Date__c  < NEXT_N_DAYS:1) 
 AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = FALSE
  AND
   
 Opportunity__r.RecordTypeId IN ('0122X000000ie1A')
 
        AND
Opportunity__r.CiWF_Payment_Method__c ='Payroll Giving'
AND
Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01
AND
Transaction_Allocation__c.GL_Code__c IN ('50090', '50030')
 
 )
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count,    Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50020','50050','50060','50200') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)
AND
Transaction_Allocation__c.Amount__c > 499 
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, sum(Transaction_Allocation__c.Amount__c) amount,   Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50020','50050','50060','50200') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount,COUNT_DISTINCT(Opportunity__r.Id) The_Count,   Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','012w00000006jGo')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50020','50050','50060','50200') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount,COUNT_DISTINCT(Opportunity__r.Id) The_Count,   Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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
((
Opportunity__r.RecordTypeId IN ('012w00000006jGy')
 AND
Opportunity__r.Date_Recurring_Donation_Established__c  > 2022-03-31
 
)
OR
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = False))
 
AND
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')
AND
Opportunity__r.Contact_Earliest_Record_Date__c<= 2022-03-31)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, sum(Transaction_Allocation__c.Amount__c) amount,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  > 2022-03-31
)
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = False))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal','Agency','Payroll Giving','Standing Order')
 
AND
Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
from Transaction_Allocation__c
where 
(
  Transaction_Allocation__c.Stage__c IN ('Posted','Refunded','Failed','Refund','Reversal')
 
AND
  
     (Transaction_Allocation__c.Close_Date__c  > 2022-03-31 AND                Transaction_Allocation__c.Close_Date__c  < NEXT_N_DAYS:1) 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True
 
AND
   
 Opportunity__r.RecordTypeId IN ('0122X000000ie1A')
 
        AND
Opportunity__r.CiWF_Payment_Method__c !='Paypal'
 
AND Transaction_Allocation__c.GL_Code__c IN ('50030','50090')
 )
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
 
AND Transaction_Allocation__c.Stage__c IN ('Posted')
 
AND
Opportunity__r.RecordTypeId ='012w00000006jGy'
AND
Transaction_Allocation__c.GL_Code__c IN ('50030', '50090')     
 
AND
Opportunity__r.Recurring_Donation_Installment_Period__c != 'Monthly'

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count,sum(Transaction_Allocation__c.Amount__c) amount,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, COUNT_DISTINCT(Opportunity__r.Id) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 ('50020','50050','50060','50200')
AND 
Opportunity__r.Contact_Earliest_Record_Date__c> 2022-03-31
AND
Opportunity__r.RecordTypeId IN ('012w00000006jGo','012w0000000hbgn','012w0000000MQol') 


Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count,sum(Transaction_Allocation__c.Amount__c) amount,   Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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','50090')
AND Opportunity__r.Contact_Earliest_Record_Date__c> 2022-03-31
AND
((Opportunity__r.RecordTypeId IN ('012w00000006jGy') 
AND Opportunity__r.Date_Recurring_Donation_Established__c > 2022-03-31)
OR
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = False))
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count_Distinct(Opportunity__r.Id) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years 
 
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
((
Opportunity__r.RecordTypeId IN ('012w00000006jGy')
 AND
Opportunity__r.Date_Recurring_Donation_Established__c  > 2022-03-31
 
)
OR
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = False))
 
AND
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')
AND
Opportunity__r.Contact_Earliest_Record_Date__c> 2022-03-31)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, 
  sum(Transaction_Allocation__c.Amount__c) amount, 
  Opportunity__r.CiWF_Payment_Method__c, 
  Opportunity__r.Country_of_Ownership__c, 
  Opportunity__r.CurrencyIsoCode, 
  CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50020','50050','50060','50200') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c> 2022-03-31)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, 
  Opportunity__r.Country_of_Ownership__c,
  Opportunity__r.CurrencyIsoCode, 
  CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),
  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, sum(Transaction_Allocation__c.Amount__c) amount, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','012w00000006jGo')
 
AND Transaction_Allocation__c.GL_Code__c IN ('50020','50050','50060','50200') )
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
COUNT_DISTINCT(Opportunity__r.Id) The_Count, sum(Transaction_Allocation__c.Amount__c) amount, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')

OR 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','0122X000000ie1F','012w00000006jGe','012w00000006jGo','012w00000006jGy','0122X000000ie1A')
                                    
 
AND Transaction_Allocation__c.GL_Code__c IN ('50110') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years

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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','0122X000000ie1F','012w00000006jGe','012w00000006jGo','012w00000006jGy','0122X000000ie1A')
                                    
 
AND Transaction_Allocation__c.GL_Code__c IN ('50130')) 


Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years

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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','0122X000000ie1F','012w00000006jGe','012w00000006jGo','012w00000006jGy','0122X000000ie1A')
                                    
 
AND Transaction_Allocation__c.GL_Code__c IN ('51060') 
AND  Opportunity__r.Contact_Earliest_Record_Date__c< 2022-04-01)

Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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.TA_GL_Category__c = 'Raffle Ticket Sales (51020)'
)
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
 
Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c IN ('Fundraised Sales (51040)','Book Sales (51050)'
))
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
 
Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c IN ('Fundraised Sales (51040)','Book Sales (51050)'
))
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
 
Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c IN ('Fundraised Sales (51040)','Book Sales (51050)'
))
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 
 
Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','012w00000006jGo')
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c IN ('Fundraised Sales (51040)','Book Sales (51050)'
))
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','012w00000006jGe','0122X000000ie1F')
  
AND
 
Transaction_Allocation__c.TA_GL_Category__c = 'In Memory Of (IMO) (50170)'
)
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c = 'FAV Donation (50060)'
)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn')
 
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c = 'Appeal (50050)'
)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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 Opportunity__r.RecordTypeId IN ('012w0000000MQol','012w0000000hbgn','012w00000006jGo')
 
 
AND
 
Transaction_Allocation__c.TA_GL_Category__c = 'Donation (50020)'
)
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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
Opportunity__r.CiWF_Payment_Method__c = 'Direct Debit'
     
AND
Transaction_Allocation__c.GL_Code__c IN ('50030', '50090'))
AND
((Opportunity__r.RecordTypeId ='012w00000006jGy'
AND
Opportunity__r.Recurring_Donation_Installment_Period__c != 'Monthly')
 
OR 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A')
AND
Opportunity__r.CiWF_Payment_Method__c != 'Paypal')))
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count(Transaction_Allocation__c.Amount__c) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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
Opportunity__r.CiWF_Payment_Method__c IN ('Standing Order','Agency','Payroll Giving'))
AND
Transaction_Allocation__c.GL_Code__c IN ('50030', '50090')
 AND
   
 Opportunity__r.RecordTypeId IN ('012w00000006jGy','0122X000000ie1A')
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
select
sum(Transaction_Allocation__c.Amount__c) amount, count_Distinct(Opportunity__r.Id) The_Count, Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c, Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c) Months,  CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c) Years
 
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','50090')) 
AND
 
((Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly'
 
AND Opportunity__r.RecordTypeId IN ('012w00000006jGy'))
 
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A')
 
AND Opportunity__r.CiWF_Payment_Method__c IN ('Paypal')))
 
 
Group by Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode, CALENDAR_MONTH(Transaction_Allocation__c.Close_Date__c),CALENDAR_YEAR(Transaction_Allocation__c.Close_Date__c)
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.GL_Code__c IN ('50140','50180','50181','50270','50260','50141') 
AND
Transaction_Allocation__c.Stage__c IN ('Ask Made', 'Identify','Research','Plan','Engage','Prepare Ask','Pledged','Posted','Refunded','Failed','Refund','Reversal') 

AND
Transaction_Allocation__c.Close_Date__c  > 2022-03-31 AND Transaction_Allocation__c.Close_Date__c  < NEXT_N_DAYS:1 

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
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.GL_Code__c IN ('50140','50180','50181','50270','50260','510141') 
AND
Transaction_Allocation__c.Stage__c IN ('Ask Made', 'Identify','Research','Plan','Engage','Prepare Ask','Pledged','Posted','Refunded','Failed','Refund','Reversal') 
AND
 Opportunity__r.RecordTypeId NOT IN ('012w00000006jGy','0122X000000ie1A')

AND
((Transaction_Allocation__c.Stage__c IN ('Posted','Refunded','Failed','Refund','Reversal') 
AND
Transaction_Allocation__c.Close_Date__c  > 2022-03-31 AND Transaction_Allocation__c.Close_Date__c  < NEXT_N_DAYS:1 
AND
(Opportunity__r.Pledge_Date__c > 2022-03-31
OR
Opportunity__r.Pledge_Date__c =null))
OR
(Transaction_Allocation__c.Stage__c IN ('Ask Made', 'Identify','Research','Plan','Engage','Prepare Ask','Pledged') 
AND
Opportunity__r.Pledge_Date__c > 2022-03-31))

 
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
select Transaction_Allocation__c.Close_Date__c,
  COUNT_DISTINCT(Opportunity__r.Id) The_Count,
  sum(Transaction_Allocation__c.Amount__c) amount,  
  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR
 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))
 
AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
 
 
Group by Transaction_Allocation__c.Close_Date__c,Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c , Opportunity__r.CurrencyIsoCode
select Transaction_Allocation__c.Close_Date__c,COUNT_DISTINCT(Opportunity__r.Id) The_Count,sum(Transaction_Allocation__c.Amount__c) amount,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,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.Amount__c <0
AND 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR

(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))

AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
AND
Opportunity__r.CampaignId = '7014J000000MQ63QAG'


Group by Transaction_Allocation__c.Close_Date__c,Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c , Opportunity__r.CurrencyIsoCode
select Transaction_Allocation__c.Close_Date__c,COUNT_DISTINCT(Opportunity__r.Id) The_Count,sum(Transaction_Allocation__c.Amount__c) amount,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,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 
((Opportunity__r.RecordTypeId IN ('012w00000006jGy')
And
Opportunity__r.Date_Recurring_Donation_Established__c  < 2022-04-01
AND
Opportunity__r.Recurring_Donation_Installment_Period__c = 'Monthly')
OR

(Opportunity__r.RecordTypeId IN ('0122X000000ie1A') 
AND
Opportunity__r.Direct_Regular_Donor_Start_of_FY__c = True))

AND 
Transaction_Allocation__c.GL_Code__c IN ('50030','50090')) 
AND
 Opportunity__r.CiWF_Payment_Method__c IN ('Credit/Debit Card','Direct Debit','Paypal')
AND
Opportunity__r.CampaignId = '7014J000000MQ63QAG'


Group by Transaction_Allocation__c.Close_Date__c,Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c , Opportunity__r.CurrencyIsoCode
select Transaction_Allocation__c.Close_Date__c,sum(Transaction_Allocation__c.Amount__c) amount,COUNT_DISTINCT(Opportunity__r.Id) The_Count,  Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,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
Opportunity__r.CiWF_Payment_Method__c = 'Direct Debit'
     
AND
Transaction_Allocation__c.GL_Code__c IN ('50030', '50090'))
AND
((Opportunity__r.RecordTypeId ='012w00000006jGy'
AND
Opportunity__r.Recurring_Donation_Installment_Period__c != 'Monthly')
 
OR 
(Opportunity__r.RecordTypeId IN ('0122X000000ie1A')
AND
Opportunity__r.CiWF_Payment_Method__c != 'Paypal')))



Group by Transaction_Allocation__c.Close_Date__c,Opportunity__r.CiWF_Payment_Method__c, Opportunity__r.Country_of_Ownership__c,Opportunity__r.CurrencyIsoCode
star

Fri Mar 31 2023 13:32:26 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Fri Mar 31 2023 13:07:48 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Wed Mar 22 2023 15:25:37 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Wed Mar 22 2023 14:59:46 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Jan 09 2023 12:36:29 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Dec 13 2022 17:36:24 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Thu Sep 29 2022 16:33:27 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Thu Sep 29 2022 14:47:04 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Fri Sep 23 2022 08:42:59 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Thu Sep 15 2022 09:02:08 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Wed Sep 14 2022 08:54:26 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Thu Sep 08 2022 13:28:59 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 16:27:35 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 14:28:40 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 14:16:36 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 14:13:18 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 13:52:45 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 12:45:25 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 12:43:09 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 12:34:30 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 12:28:33 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 11:22:38 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 11:13:58 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 11:06:34 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 11:05:13 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 10:47:42 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 10:40:02 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 10:38:52 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 10:33:16 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 10:16:12 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 10:07:23 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 09:56:05 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 09:29:33 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 09:10:20 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 09:04:51 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 08:48:03 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 08:46:10 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Aug 16 2022 08:30:01 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:29:22 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:29:21 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:29:17 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:29:13 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:25:59 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:15:31 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:11:00 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:05:05 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 16:00:37 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 15:55:35 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Aug 15 2022 15:41:20 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Fri Jul 15 2022 13:59:14 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Fri Jul 15 2022 12:50:28 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Wed Jul 13 2022 10:14:53 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Fri Jul 08 2022 12:34:55 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Mon Jun 27 2022 10:51:17 GMT+0000 (Coordinated Universal Time)

#gigkpi
star

Tue Apr 26 2022 08:57:27 GMT+0000 (Coordinated Universal Time)

#gigkpi

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension