Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Metric and Definition

Query

Comments and Business Use

Known Diner Sales (“KDS”)

All sales that are made by recognizable guests, i.e. guests that have registered through the app (identified by their registered account id beginning with ‘us-east’)

Code Block
languagesql
SELECT TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
SUM(AMOUNT) AS SALES,
COUNT(DISTINCT TICKET_ID) AS TRXNS,
COUNT(DISTINCT REGISTERED_ACCOUNT_ID) AS GUESTS

FROM STG.DERIVED_MASTER_TABLE_NEW

WHERE 
PARTITION_DATE_KEY BETWEEN '<START DATE>' AND '<END DATE>'
AND IS_PASS_THROUGH = 0
AND COUNTRY_NM = 'CANADA'
AND LEFT(REGISTERED_ACCOUNT_ID,7) = 'us-east'

GROUP BY 1,2

This metric is used as a baseline to see loyalty sales penetration against system wide sales.

System Wide Sales (“SWS”)

Total sales across TH

Code Block
languagesql
SELECT
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
COUNT(DISTINCT TICKET_ID) AS TRXNS,
SUM(AMOUNT) AS SWS

FROM STG.DERIVED_MASTER_TABLE_NEW 
      
WHERE 
PARTITION_DATE_KEY BETWEEN '<START DATE>' AND '<END DATE>'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = 'CANADA'

GROUP BY 1,2

Note: Some forecasts may use Hyperion sales interchangeable in lieu of SWS sourced from STG.DERIVED_MASTER_TABLE_NEW.

Cheque

Average sales value ($) of an individual transaction

Code Block
languagesql
SELECT
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
COUNT(DISTINCT TICKET_ID) AS TRXNS,
SUM(AMOUNT) AS SWS,
SUM(AMOUNT)/COUNT(DISTINCT TICKET_ID) AS CHEQUE

FROM STG.DERIVED_MASTER_TABLE_NEW 
      
WHERE 
PARTITION_DATE_KEY BETWEEN '<START DATE>' AND '<END DATE>'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = 'CANADA'

GROUP BY 1,2

Can calculate this on a system level or down to an individual guest level. Can filter on loyalty or non-loyalty.

Frequency

Average loyalty guest visits in a given time period

Code Block
languagesql
SELECT
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
COUNT(DISTINCT TICKET_ID) AS TRXNS,
COUNT(DISTINCT REGISTERED_ACCOUNT_ID) AS GUESTS,
COUNT(DISTINCT TICKET_ID)/COUNT(DISTINCT T1.REGISTERED_ACCOUNT_ID) AS FREQUENCY

FROM STG.DERIVED_MASTER_TABLE_NEW T1
      
WHERE 
PARTITION_DATE_KEY BETWEEN '<START DATE>' AND '<END DATE>'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = 'CANADA'
AND LEFT(REGISTERED_ACCOUNT_ID,7) = 'us-east'

GROUP BY 1,2

Usually look at this metric for a week, month, or year.

White Label Delivery (“WL”)

Delivery sales initiated from the TH mobile app

Code Block
languagesql
SELECT 
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
SUM(AMOUNT) AS SALES

FROM STG.DERIVED_MASTER_TABLE_NEW 

WHERE PARTITION_DATE_KEY BETWEEN '$START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = "CANADA"
AND SERVICE_MODE_CD IN ('WHITE LABEL DELIVERY','DELIVERY')
AND LEFT(REGISTERED_ACCOUNT_ID,7) = 'us-east'

GROUP BY 1,2

Included in known diner sales & digital sales.

Sales of our internal app delivery platform.

Mobile Order & Pay (“MO&P”)

Code Block
languagesql
SELECT 
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
SUM(AMOUNT) AS SALES

FROM STG.DERIVED_MASTER_TABLE_NEW 

WHERE PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = "CANADA"
AND SERVICE_MODE_CD IN ('MOBILE ORDER DRIVE THRU', 'MOBILE ORDER EAT IN', 'MOBILE ORDER TAKE OUT')
AND LEFT(REGISTERED_ACCOUNT_ID,7) = 'us-east'

GROUP BY 1,2

Included in known diner sales & digital sales.

Loyalty Scans

Sales made by known diners and includes eat-in, takeout & drive thru

Code Block
languagesql
SELECT 
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
SUM(AMOUNT) AS SALES

FROM STG.DERIVED_MASTER_TABLE_NEW 

WHERE PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = "CANADA"
AND SERVICE_MODE_CD IN ('TAKEOUT', 'EATIN','DRIVETHRU')
AND LEFT(REGISTERED_ACCOUNT_ID,7) = 'us-east'

GROUP BY 1,2

Included in known diner sales & digital sales.

3P Delivery

Delivery sales initiated and fulfilled by third-party delivery providers, such as UberEats, SkipTheDishes and DoorDash

Code Block
languagesql
SELECT 
A.PARTITION_DATE_KEY,
SUM(A.AMOUNT) AS SALES

FROM STG.DERIVED_MASTER_TABLE_NEW A 

INNER JOIN TLOG.TLOG_SALE_TICKET_TENDERS B 
ON A.TICKET_ID = B.TICKET_ID

WHERE A.PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0 
AND COUNTRY_NM = 'CANADA'
AND TENDER_NAME IN ("UBER EATS CREDIT","Credit Uber Eats","Uber Eats Credit","CRÉDIT UBER EATS","SKIP CREDIT","Skip Credit","CRÉDIT de DoorDash","CRÉDIT DE DOORDASH","DoorDash Credit","DOORDASH CREDIT","Crédit de DoorDash","Doordash")

GROUP BY 1

Included in digital sales

Kiosk

Sales via Kiosk; can be split into registered and un-registered Kiosk sales using left(registered_account_id,7) = ‘us-east’

Code Block
languagesql
SELECT
    LAST_DAY(PERIOD_DT) AS MONTH,
    SUM(AMOUNT) AS KIOSK_SALES,
    COUNT(DISTINCT TICKET_ID) AS KIOSK_TRXNS,
    COUNT(DISTINCT LOYALTY_CUSTOMER_ID) AS KIOSK_GUESTS
  FROM
    STG.DERIVED_MASTER_TABLE_NEW
  WHERE
    PERIOD_DT BETWEEN '$Start_Date'
    AND '$End_Date'
    AND IS_PASS_THROUGH = 0
    AND COUNTRY_NM = 'CANADA'
    AND SERVICE_MODE_CD IN ('KIOSK', 'KIOSK TAKEOUT', 'KIOSK EATIN')
    AND REST_NO IN (
    101789,<list of restaurants with KIOSKS>
101517,    )
108175,  GROUP BY
 101493,   1

Included in digital sales

Code Block
languagesql
-- Registered 102093,Kiosk
AND LEFT(COALESCE(REGISTERED_ACCOUNT_ID,''),7) =  101846,
    109331,
    102784,
    109403,
    108485,
    100525,
    106376,
    105060,
    101712,
    103498,
    109951,
    103637,
    102534,
    100410,
    100062,
    104505,
    104853,
    103482,
    103389,
    103227,
    103217,
    102614,
    100788,
    108397,
    100112,
    105789,
    100806,
    102549,
    107228,
    101475,
    101657,
    100674,
    102011,
    101129,
    104420,
    104764,
    106305,
    101000,
    109241,
    108358,
    103413,
    100027,
    100526,
    104213,
    103704,
    105217,
    104402,
    104271,
    102946,
    102376,
    102229,
    103233,
    100940,
    104962,
    101491,
    102118,
    102732,
    107384,
    101803,
    100446,
    109041,
    109757,
    101917,
    109878,
    102169,
    104840,
    104013,
    108507,
    101886,
    100136,
    100514,
    102017,
    102974,
    101900,
    105085,
    100467,
    100490,
    103690,
    102467,
    102305,
    104925,
    103167,
    101382,
    108487,
    103648,
    101281,
    102110,
    100045,
    102398,
    103850,
    107647,
    102753,
    103124,
    102224,
    100678,
    106882,
    101865,
    100652,
    100503,
    100693,
    102040,
    109449,
    108102,
    105389,
    103695,
    101666,
    101076,
    100529,
    100376,
    100856,
    102606,
    101582,
    106547,
    107608,
    100325,
    100324,
    103340,
    102417,
    103129,
    100544,
    101365,
    105340,
    102074,
    100096,
    108167,
    108166,
    108088,
    107336,
    104443,
    103384,
    103255,
    103208,
    103356,
    101450,
    103202,
    104284,
    104856,
    101241,
    102331,
    104393,
    101820,
    104126,
    101333,
    102556,
    102972,
    104471,
    103568,
    105792,
    103021,
    103143,
    102833,
    103086,
    101991,
    108399,
    109334,
    109955,
    101462,
    100582,
    100124,
    108500,
    107576,
    101335,
    109291,
    103677,
    107569,
    102635,
    105237,
    100160,
    103077,
    102622,
    101818,
    105917,
    101600,
    102308,
    103029,
    101992,
    102603,
    103947,
    103137,
    108172,
    101022,
    103050,
    106865,
    103323,
    106310,
    103169,
    102399,
    102018,
    101595,
    103407,
    101655,
    100101,
    100506,
    100093,
    100863,
    103625,
    103279,
    102891,
    101999,
    101543,
    101476,
    102562,
    100024,
    104852,
    104370,
    109430,
    108502,
    102852,
    103644,
    101623,
    109405,
    101837,
    100200,
    101568,
    100885,
    100104,
    101628,
    102991,
    102773,
    102877,
    103548,
    102821,
    102103,
    103411,
    104887,
    102196,
    102315,
    109027,
    100998,
    102630,
    102394,
    108402,
    101650,
    109042,
    101873,
    103755,
    102925,
    103478,
    109407,
    109397,
    109396,
    109338,
    109286,
    109246,
    107582,
    103584,
    101967,
    104970,
    106478,
    104212,
    102212,
    101508,
    101368,
    100800,
    100077,
    103950,
    103698,
    102132,
    101851,
    105363,
    100670,
    102157,
    108115,
    103001,
    103955,
    102892,
    103130,
    101769,
    101357,
    101904,
    100118,
    101864,
    101686,
    101174,
    101924,
    109711,
    104289,
    103886,
    102710,
    101689,
    101442,
    109404,
    109780,
    109447,
    103351,
    100640,
    104813,
    102387,
    104275,
    109444,
    101584,
    109448,
    108480,
    108395,
    105840,
    104651,
    103132,
    102679,
    107653,
    106874,
    105763,
    102646,
    101849,
    100229,
    108430,
    101985,
    102150,
    101871,
    102719,
    102060,
    120293,
    100965,
    109436,
    108137,
    100776,
    108118,
    100387,
    102041,
    103754,
    102409,
    102032,
    101602,
    108518,
    100769,
    101788,
    109288,
    103159,
    101954,
    109446,
    103294,
    103549,
    104391,
    102129,
    102175,
    100015,
    101528,
    102171,
    100967,
    103073,
    101308,
    101552,
    100738,
    101535,
    103702,
    101870,
    103591,
    102274,
    101159,
    102593,
    101200,
    100255,
    103659,
    104966,
    105920,
    100489,
    100568,
    100588,
    101339,
    102001,
    103267,
    107343,
    103634
    )
  GROUP BY
    1

Included in digital sales

Code Block
languagesql
-- Registered Kiosk
AND LEFT(COALESCE(REGISTERED_ACCOUNT_ID,''),7) = 'us-east'
-- Un-Registered Kiosk
AND LEFT(COALESCE(REGISTERED_ACCOUNT_ID,''),7) != 'us-east'

Catering

Catering sales

Code Block
languagesql
SELECT 
PARTITION_DATE_KEY,
SUM(ITEMTOTALPRICE)AS SALES,

FROM PRODRT.CURATED_TRANS_EVENTS_NEW

WHERE PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND COUNTRY_NM = 'CANADA'
AND IS_PASS_THROUGH = 0 
AND LEFT(REGISTEREDACCOUNTID,7) = 'us-east'
AND DININGTYPE = 'CT'

GROUP BY 1

Included in digital sales

Restaurants Reporting Any Menu Item (“RRAMI“)

Code Block
languagesql
WITH RESTAURANTS AS (

SELECT 

TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
PARTITION_DATE_KEY,
COUNT(DISTINCT REST_NO) AS RESTAURANTS

FROM STG.DERIVED_MASTER_TABLE_NEW

WHERE PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0
AND COUNTRY_NM = 'CANADA' 

GROUP BY 1,2,3
ORDER BY 1)

SELECT 
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
SUM(RESTAURANTS) AS RRAMI

FROM RESTAURANTS

GROUP BY 1,2

Scan & Pay (“S&P”)

Transactions where Scan & Pay feature was used

Code Block
languagesql
SELECT 
STOREDATE,
COUNT(DISTINCT TRANSACTIONID) AS TICKETS,
SUM(ITEMTOTALPRICE) AS SALES 

FROM PRODRT.CURATED_TRANS_EVENTS_NEW

WHERE STOREDATE BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0
AND COUNTRY_NM IN ('CANADA')
AND LEFT(REGISTEREDACCOUNTID,7) = 'us-east'
AND SCANANDPAY IS TRUE

GROUP BY 1

Often tracked as a % of registered transactions

Scan & Pay Penetration Formula: (Scan & Pay Transactions) / (Registered Transactions)

Loyalty Redemptions

Products that were redeemed using loyalty points

Code Block
languagesql
CACHE TABLE DAILY_REDEMPTIONS AS

WITH TRANSACTIONS_WITH_OFFER_ID AS (

SELECT 
LEFT(PERIOD_DT, 10) AS PERIOD_DT,
REGISTEREDACCOUNTID,
TRANSACTIONID, 
EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS

FROM PRODRT.CURATED_TRANS_EVENTS_NEW

WHERE DATE_KEY >= '20230606'
AND COALESCE(REGISTEREDACCOUNTID,'') IS NOT NULL
AND APPLIEDOFFERS IS NOT NULL
AND COUNTRY_NM = 'CANADA')

SELECT 
PERIOD_DT,
COUNT(DISTINCT TRANSACTIONID) AS TRXNS

FROM TRANSACTIONS_WITH_OFFER_ID AS A

INNER JOIN (SELECT DISTINCT OFFERID FROM DYDB.WEEKLYOFFERS
             
            UNION ALL
            
            SELECT DISTINCT OFFERID
            FROM DYDB.OFFERS
            WHERE CONTAINS(description, 'LOYALTY')
            AND DESCRIPTION LIKE 'CA L%'
            AND DESCRIPTION NOT IN ('CA LR Registered Default (same as L1)-LOYALTY', 'CA LU Unregistered (same as 102) ONE-TIME-LOYALTY') ) B
            
ON A.EXPLODED_OFFERS = B.OFFERID 

LEFT JOIN DYDB.OFFERS AS C 
ON A.EXPLODED_OFFERS=C.OFFERID

WHERE EXPLODED_OFFERS IS NOT NULL 
AND C.OFFERID IS NOT NULL

GROUP BY 1

Used for tracking how many free items we’re giving away and the value of them.

Often viewed as a percentage of SWS or KDS.

Loyalty drag formula = $ value of redeemed items / SWS $

Monthly Active Users (“MAU”)

Number of guests that visited the app each month

Code Block
languagesql
WITH EVENTS AS (
SELECT DATE
       , _TIMHORTONS.INTERACTION.ELEMENT.NAME
       , _TIMHORTONS.LOYALTY.ID AS GUEST_ID
FROM   loyalty.events.adobe_app_events
WHERE  EVENTTYPE IN ('app_open','app_launch')    
AND    _TIMHORTONS.PLATFORM IN ('app') 
AND    LEFT(_TIMHORTONS.LOYALTY.ID,7) = 'us-east'
AND    DATE <= CURRENT_DATE )

SELECT     LAST_DAY(EVENTS.DATE) AS DTE'us-east'
-- Un-Registered Kiosk
AND LEFT(COALESCE(REGISTERED_ACCOUNT_ID,''),7) != 'us-east'


-- List of Retaurants as of june 2024
('100024',	'100027',	'100045',	'100062',	'100077',	'100093',	'100096',	'100101',	'100104',	'100112',	'100118',	'100124',	'100136',	'100160',	'100200',	'100229',	'100324',	'100325',	'100376',	'100387',	'100410',	'100446',	'100467',	'100489',	'100490',	'100503',	'100506',	'100514',	'100525',	'100526',	'100529',	'100544',	'100582',	'100588',	'100640',	'100652',	'100670',	'100674',	'100678',	'100693',	'100769',	'100776',	'100788',	'100800',	'100806',	'100856',	'100863',	'100885',	'100940',	'100965',	'100998',	'101000',	'101022',	'101076',	'101129',	'101174',	'101241',	'101281',	'101333',	'101335',	'101357',	'101365',	'101368',	'101382',	'101442',	'101450',	'101475',	'101476',	'101491',	'101493',	'101508',	'101517',	'101543',	'101568',	'101582',	'101584',	'101595',	'101600',	'101602',	'101623',	'101628',	'101650',	'101655',	'101657',	'101666',	'101686',	'101689',	'101712',	'101769',	'101788',	'101789',	'101803',	'101818',	'101820',	'101837',	'101846',	'101849',	'101851',	'101864',	'101865',	'101873',	'101886',	'101900',	'101904',	'101924',	'101954',	'101967',	'101985',	'101991',	'101992',	'101999',	'102011',	'102017',	'102018',	'102032',	'102040',	'102041',	'102060',	'102074',	'102103',	'102110',	'102118',	'102129',	'102132',	'102150',	'102157',	'102169',	'102175',	'102196',	'102212',	'102224',	'102305',	'102308',	'102315',	'102331',	'102376',	'102387',	'102394',	'102398',	'102399',	'102409',	'102417',	'102467',	'102478',	'102534',	'102549',	'102556',	'102562',	'102603',	'102606',	'102614',	'102622',	'102630',	'102635',	'102646',	'102679',	'102710',	'102719',	'102732',	'102753',	'102773',	'102784',	'102821',	'102833',	'102852',	'102877',	'102891',	'102892',	'102925',	'102946',	'102972',	'102974',	'102991',	'103001',	'103021',	'103029',	'103050',	'103077',	'103086',	'103124',	'103129',	'103130',	'103132',	'103137',	'103143',	'103159',	'103167',	'103169',	'103208',	'103217',	'103227',	'103233',	'103255',	'103267',	'103294',	'103323',	'103340',	'103351',	'103356',	'103384',	'103389',	'103407',	'103411',	'103413',	'103478',	'103482',	'103498',	'103548',	'103549',	'103584',	'103625',	'103637',	'103644',	'103677',	'103690',	'103695',	'103698',	'103704',	'103754',	'103755',	'103850',	'103886',	'103947',	'103950',	'103955',	'104013',	'104126',	'104212',	'104213',	'104275',	'104284',	'104370',	'104391',	'104393',	'104420',	'104443',	'104505',	'104651',	'104764',	'104813',	'104840',	'104852',	'104853',	'104856',	'104887',	'104925',	'104962',	'104966',	'104970',	'104971',	'105060',	'105085',	'105217',	'105237',	'105340',	'105363',	'105389',	'105763',	'105789',	'105792',	'105840',	'105917',	'106305',	'106310',	'106478',	'106547',	'106865',	'106874',	'106882',	'107228',	'107336',	'107343',	'107384',	'107569',	'107576',	'107582',	'107608',	'107647',	'107653',	'108088',	'108102',	'108115',	'108118',	'108137',	'108166',	'108167',	'108172',	'108175',	'108358',	'108395',	'108397',	'108399',	'108402',	'108430',	'108480',	'108485',	'108487',	'108500',	'108502',	'108507',	'108518',	'109027',	'109041',	'109042',	'109241',	'109246',	'109286',	'109288',	'109291',	'109331',	'109334',	'109338',	'109396',	'109397',	'109403',	'109404',	'109405',	'109407',	'109430',	'109436',	'109444',	'109446',	'109447',	'109448',	'109449',	'109711',	'109757',	'109780',	'109878',	'109951',	'109955',	'120293',	'101462',	'101917',	'102093',	'102229',	'103202',	'103648',	'104271',	'104471',	'106376')

Catering

Catering sales

Code Block
languagesql
SELECT 
PARTITION_DATE_KEY,
SUM(ITEMTOTALPRICE)AS SALES,

FROM PRODRT.CURATED_TRANS_EVENTS_NEW

WHERE PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND COUNTRY_NM = 'CANADA'
AND IS_PASS_THROUGH = 0 
AND LEFT(REGISTEREDACCOUNTID,7) = 'us-east'
AND DININGTYPE = 'CT'

GROUP BY 1

Included in digital sales

Restaurants Reporting Any Menu Item (“RRAMI“)

Code Block
languagesql
WITH RESTAURANTS AS (

SELECT 

TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
PARTITION_DATE_KEY,
COUNT(DISTINCT REST_NO) AS RESTAURANTS

FROM STG.DERIVED_MASTER_TABLE_NEW

WHERE PARTITION_DATE_KEY BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0
AND COUNTRY_NM = 'CANADA' 

GROUP BY 1,2,3
ORDER BY 1)

SELECT 
TH_FISCAL_YEAR,
TH_FISCAL_WEEK,
SUM(RESTAURANTS) AS RRAMI

FROM RESTAURANTS

GROUP BY 1,2

Scan & Pay (“S&P”)

Transactions where Scan & Pay feature was used

Code Block
languagesql
SELECT 
STOREDATE,
COUNT(DISTINCT TRANSACTIONID) AS TICKETS,
SUM(ITEMTOTALPRICE) AS SALES 

FROM PRODRT.CURATED_TRANS_EVENTS_NEW

WHERE STOREDATE BETWEEN 'START_DATE' AND 'END_DATE'
AND IS_PASS_THROUGH = 0
AND COUNTRY_NM IN ('CANADA')
AND LEFT(REGISTEREDACCOUNTID,7) = 'us-east'
AND SCANANDPAY IS TRUE

GROUP BY 1

Often tracked as a % of registered transactions

Scan & Pay Penetration Formula: (Scan & Pay Transactions) / (Registered Transactions)

Loyalty Redemptions

Products that were redeemed using loyalty points

Code Block
languagesql

WITH TRANSACTIONS_WITH_OFFER_ID AS (

SELECT 
LEFT(PERIOD_DT, 10) AS PERIOD_DT,
REGISTEREDACCOUNTID,
TRANSACTIONID, 
EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS

FROM PRODRT.CURATED_TRANS_EVENTS_NEW

WHERE DATE_KEY >= '20230606'
AND COALESCE(REGISTEREDACCOUNTID,'') IS NOT NULL
AND APPLIEDOFFERS IS NOT NULL
AND COUNTRY_NM = 'CANADA')

SELECT 
PERIOD_DT,
COUNT(DISTINCT TRANSACTIONID) AS TRXNS

FROM TRANSACTIONS_WITH_OFFER_ID AS A

INNER JOIN (SELECT DISTINCT OFFERID FROM DYDB.WEEKLYOFFERS
             
            UNION ALL
            
            SELECT DISTINCT OFFERID
            FROM DYDB.OFFERS
            WHERE CONTAINS(description, 'LOYALTY')
            AND DESCRIPTION LIKE 'CA L%'
            AND DESCRIPTION NOT IN ('CA LR Registered Default (same as L1)-LOYALTY', 'CA LU Unregistered (same as 102) ONE-TIME-LOYALTY') ) B
            
ON A.EXPLODED_OFFERS = B.OFFERID 

LEFT JOIN DYDB.OFFERS AS C 
ON A.EXPLODED_OFFERS=C.OFFERID

WHERE EXPLODED_OFFERS IS NOT NULL 
AND C.OFFERID IS NOT NULL

GROUP BY 1

Used for tracking how many free items we’re giving away and the value of them.

Often viewed as a percentage of SWS or KDS.

Loyalty drag formula = $ value of redeemed items / SWS $

Monthly Active Users (“MAU”)

Number of guests that visited the app each month

Code Block
languagesql
WITH EVENTS AS (
SELECT DATE
       , _TIMHORTONS.INTERACTION.ELEMENT.NAME
       , _TIMHORTONS.LOYALTY.ID AS GUEST_ID
FROM   loyalty.events.adobe_app_events
WHERE  EVENTTYPE IN ('app_open','app_launch')    
AND    _TIMHORTONS.PLATFORM IN ('app') 
AND    LEFT(_TIMHORTONS.LOYALTY.ID,7) = 'us-east'
AND    _TIMHORTONS.LOYALTY.ID IN (SELECT DISTINCT registeredAccountId FROM loyalty.users.customer_base WHERE LEFT(loyaltyCustomerId,4) IN ('0463','0473'))
AND    DATE <= CURRENT_DATE )

SELECT     LAST_DAY(EVENTS.DATE) AS DTE
          , COUNT(DISTINCT EVENTS.GUEST_ID) AS ACTIVE_USER
FROM      EVENTS  
GROUP BY  1
ORDER BY  1 DESC

Used to track the unique number of guests who opened or launched the app per month. Limitation of the dataset is: (1) data only exists from Nov 1st, 2023, and (2) Prior to mm/dd/yyyy (TBD), dataset did not contain guests using app versions prior to 7.1.187.

Digital Sales

Pulled using the individual queries listed above.

Consists of WL, MO&P, Loyalty Scans, 3P Delivery, Kiosk & Catering.

Weekly Offer Redemptions

Code Block
languagesql
WITH REDEMPTION_SUMMARY AS (
  WITH OFFER_REDEMPTION_TRXNS AS (
    WITH TRANSACTIONS_WITH_OFFER_ID AS (
      SELECT
        TH_FISCAL_YEAR,
        TH_FISCAL_WEEK,
        CAST(WEEK_START_DT AS DATE) AS WEEK_START_DT,
        DATE_FORMAT(
          CAST(
            UNIX_TIMESTAMP(LEFT(WEEK_START_DT, 10), 'yyyy-MM-dd') AS TIMESTAMP
          ),
          'yyyyMMdd'
        ) AS WEEK_START,
        CAST(PERIOD_DT AS DATE) AS PERIOD_DT,
        REGISTEREDACCOUNTID,
        TRANSACTIONID,
        EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS
      FROM
        PRODRT.CURATED_TRANS_EVENTS_NEW
      WHERE
        PARTITION_DATE_KEY BETWEEN 'START DATE' AND 'END DATE'
        AND REGISTEREDACCOUNTID LIKE 'us-east%'
        AND COUNTRY_NM = 'CANADA'
    )
    SELECT
      DISTINCT A.TH_FISCAL_YEAR,
      A.TH_FISCAL_WEEK,
      A.WEEK_START_DT,
      A.PERIOD_DT,
      A.REGISTEREDACCOUNTID,
      A.TRANSACTIONID,
      C.NAME,
      C.DESCRIPTION,
      A.EXPLODED_OFFERS,
      1 AS VOLUME
    FROM
      TRANSACTIONS_WITH_OFFER_ID A
      INNER JOIN DYDB.WEEKLYOFFERS B ON A.EXPLODED_OFFERS = B.OFFERID
      LEFT JOIN DYDB.OFFERS C ON A.EXPLODED_OFFERS = C.OFFERID
  )
  SELECT
    WEEK_START_DT,
    A.DESCRIPTION AS OFFER_DESCRIPTION,
    A.EXPLODED_OFFERS AS OFFERID,
    SUM(VOLUME) AS REDEMPTION_VOLUME
  FROM
    OFFER_REDEMPTION_TRXNS A
  GROUP BY
    1,
    2,
    3
)
SELECT
  a.WEEK_START_DT AS WKDT,
  OFFER_DESCRIPTION,
  OFFERID,
  SUM(REDEMPTION_VOLUME)
FROM
  REDEMPTION_SUMMARY A
  GROUP BY 1,2,3

Used to track the volume of redemptions for each offer in a given week.

Offer Challenge

Code Block
languagesql
with TRXN_OFFER_CHALLENGES_REDEMPTIONS as (
      WITH EXPLODED AS (
        SELECT
          TH_FISCAL_YEAR,
          TH_FISCAL_WEEK,
          DATE_FORMAT(
            CAST(
              UNIX_TIMESTAMP(LEFT(WEEK_START_DT, 10), 'yyyy-MM-dd') AS TIMESTAMP
            ),
            'yyyyMMdd'
          ) AS WEEK_START_MAPPING,
          CAST(PERIOD_DT AS DATE) AS PERIOD_DT,
          REGISTEREDACCOUNTID,
          loyaltyCustomerId,
          TRANSACTIONID,
          EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS,
          REST_TYP_NM,
          OPS_DIV_NM
        FROM
          PRODRT.CURATED_TRANS_EVENTS_NEW -- 1.	Challenge duration: 26/09 to 02/10
        WHERE
          DATE_KEY BETWEEN '${myapplication.Offer_Start_Date}'
          AND '${myapplication.Offer_End_Date}'
          AND COUNTRY_NM = 'CANADA'
          AND REGISTEREDACCOUNTID IS NOT NULL
          AND TRANSACTIONID IS NOT NULL -- AND REST_TYP_NM = "STANDARD"
      )
      SELECT
        DISTINCT A.TH_FISCAL_YEAR,
        A.TH_FISCAL_WEEK,
        A.WEEK_START_MAPPING,
        A.PERIOD_DT,
        A.REGISTEREDACCOUNTID,
        A.loyaltyCustomerId,
        A.TRANSACTIONID,
        A.REST_TYP_NM,
        A.OPS_DIV_NM,
        B.DESCRIPTION,
        1 AS REDEMPTIONS
      FROM
        EXPLODED AS A
        LEFT JOIN DYDB.OFFERS AS B ON A.EXPLODED_OFFERS = B.OFFERID
      WHERE
        EXPLODED_OFFERS = '76290e2e-1783-442f-8ff6-a2b16900a34e'
    ),
    points_issued as (
      Select
        *,
        WEEKOFYEAR(to_date(partition_date_key, "yyyyMMdd")) AS WEEK_START,
        regexp_extract(barcode, '(\\d+)|(\\d+)', 0) as lid
      From
        prodrt.curated_points_events as points
      where
        partition_date_key BETWEEN '${myapplication.Offer_Start_Date}'
        AND '${myapplication.Offer_End_Date}'
        and tag = 'PRODUCT_CHALLENGED_COMPLETED'
    ),
    completed as(
      Select
        a.TH_FISCAL_YEAR as TH_FISCAL_YEAR,
        a.TH_FISCAL_WEEK as TH_FISCAL_WEEK,
        a.WEEK_START_MAPPING as WEEK_START_MAPPING,
        a.PERIOD_DT as PERIOD_DT,
        DATE_FORMAT(
          CAST(
            UNIX_TIMESTAMP(LEFT(PERIOD_DT, 10), 'yyyy-MM-dd') AS TIMESTAMP
          ),
          'yyyyMMdd'
        ) as transaction_dt,
        a.REGISTEREDACCOUNTID as REGISTEREDACCOUNTID,
        a.loyaltyCustomerId as loyaltyCustomerId,
        a.TRANSACTIONID as TRANSACTIONID,
        a.REST_TYP_NM as REST_TYP_NM,
        a.OPS_DIV_NM as OPS_DIV_NM,
        a.DESCRIPTION as DESCRIPTION,
        a.REDEMPTIONS as REDEMPTIONS,
        b.transactionID as completion_transactionID,
        b.pointsEarned as pointsEarned,
        b.restaurant as restaurant,
        b.partition_date_key as offer_completion_dt,
        b.WEEK_START as offer_completion_week,
        b.lid as lid
      from
        TRXN_OFFER_CHALLENGES_REDEMPTIONS a
        left join points_issued b on a.loyaltyCustomerId = b.lid
        and b.WEEK_START = a.TH_FISCAL_WEEK
    )
    Select
      TH_FISCAL_YEAR,
      TH_FISCAL_WEEK,
      WEEK_START_MAPPING,
      REGISTEREDACCOUNTID,
      loyaltyCustomerId,
      offer_completion_week,
      count(
        distinct(
          case
            when offer_completion_dt is not NULL
            and transaction_dt <= offer_completion_dt then TRANSACTIONID
          end
        )
      ) as trnx_before_completion,
      count(distinct(TRANSACTIONID)) as total_trnx,
      count(
        distinct (
          case
           , COUNT(DISTINCT EVENTS.GUEST_ID) AS ACTIVE_USER
FROM when lid is not Null then lid
    EVENTS   GROUP BY  1end
ORDER BY  1 DESC

Used to track the unique number of guests who opened or launched the app per month. Limitation of the dataset is: (1) data only exists from Nov 1st, 2023, and (2) Prior to mm/dd/yyyy (TBD), dataset did not contain guests using app versions prior to 7.1.187.

Digital Sales

Pulled using the individual queries listed above.

Consists of WL, MO&P, Loyalty Scans, 3P Delivery, Kiosk & Catering.

Weekly Offer Redemptions

Code Block
languagesql
WITH REDEMPTION_SUMMARY AS (
  WITH OFFER_REDEMPTION_TRXNS AS (
    WITH TRANSACTIONS_WITH_OFFER_ID AS (
      SELECT
        TH_FISCAL_YEAR,
     )
      ) as completed
    from
      completed
    group by 1, 2, 3, 4, 5, 6

Count of guests who completed a specific Offer Challenge

Games

NHL Hockey Challenge & Tims Word Challenge

Code Block
languagesql
SELECT    YEAR(TIMESTAMP) AS YR
          TH_FISCAL_WEEK,         CAST(WEEK_START_DT AS DATEMONTH(TIMESTAMP) AS WEEK_START_DT,MTH 
       DATE_FORMAT(   , COUNT(DISTINCT GUESTS) AS GUESTS   FROM CAST(
-- WORD CHALLENEGE PLAYERS

SELECT      DISTINCT UNIX_TIMESTAMP(LEFT(WEEK_START_DT, 10), 'yyyy-MM-dd'), _TIMHORTONS.LOYALTY.ID AS TIMESTAMPGUESTS
FROM      loyalty.events.adobe_app_events 
WHERE  ),
    TRIM(_TIMHORTONS.INTERACTION.PATH) IN ('/timswordchallenge')
AND       TRIM(_TIMHORTONS.INTERACTION.ELEMENT.NAME) = 'yyyyMMddplay'
AND       _TIMHORTONS.PLATFORM IN ('app')
AND   AS WEEK_START,   LEFT(_TIMHORTONS.LOYALTY.ID,7) = 'us-east'
AND   CAST(PERIOD_DT AS DATE) AS PERIOD_DT,
        REGISTEREDACCOUNTID,
  _TIMHORTONS.LOYALTY.ID IN (SELECT DISTINCT registeredAccountId FROM loyalty.users.customer_base WHERE LEFT(loyaltyCustomerId,4) IN ('0463','0473'))
AND      TRANSACTIONID, DATE >= DATE '2023-11-01' 

UNION
 EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS
-- HOCKEY PLAYERS

SELECT    DISTINCT  FROM
  TIMESTAMP,_TIMHORTONS.LOYALTY.ID  AS GUESTS
FROM      PRODRTloyalty.events.CURATEDadobe_TRANS_EVENTS_NEW
      app_events
WHERE     TRIM(_TIMHORTONS.INTERACTION.PATH) = '/hockey_challenge'
AND PARTITION_DATE_KEY BETWEEN 'START DATE' AND 'END DATE'
   TRIM(_TIMHORTONS.INTERACTION.ELEMENT.NAME) IN ('submit_picks')
AND      AND REGISTEREDACCOUNTID LIKE 'us-east%'
_TIMHORTONS.PLATFORM IN ('app')
AND        AND COUNTRY_NMLEFT(_TIMHORTONS.LOYALTY.ID,7) = 'CANADAus-east'
AND    )   _TIMHORTONS.LOYALTY.ID IN (SELECT DISTINCT registeredAccountId     DISTINCT A.TH_FISCAL_YEAR,
      A.TH_FISCAL_WEEK,
FROM loyalty.users.customer_base WHERE LEFT(loyaltyCustomerId,4) IN ('0463','0473'))
AND      A.WEEK_START_DT,
      A.PERIOD_DT,
      A.REGISTEREDACCOUNTID,
      A.TRANSACTIONID,
      C.NAME, DATE >= DATE '2023-11-01' 
)
GROUP BY 1,2
ORDER BY 1 DESC, 2

Count of guests who played Games (NHL Hockey Challenge and Tims Word Challenge).

Limitation: Data only available from Nov 1, 2023.

Total Sales and Ticket Count by Tender Type

Code Block
languagesql
WITH LOYALTY_TENDERS AS
(
    WITH TENDERS AS
    (
      C.DESCRIPTION,SELECT
      A.EXPLODED_OFFERS,
   REPLACE(UPPER(TRIM(TENDER_NAME)), '.', '') AS TENDER_NAME,
  1 AS VOLUME  TICKET_ID

 FROM       TRANSACTIONS_WITH_OFFER_ID AFROM loyalty.tlog.tlog_sale_ticket_tenders

      INNER JOIN DYDB.WEEKLYOFFERS B ON A.EXPLODED_OFFERS = B.OFFERIDWHERE PARTITION_DATE_KEY BETWEEN 20230101 AND 20230731
        LEFT JOIN DYDB.OFFERS C ON A.EXPLODED_OFFERS = C.OFFERIDAND LEFT(REST_NO,2) = 10
    ),

 SELECT   LOYALTY AS
WEEK_START_DT,    (
A.DESCRIPTION AS OFFER_DESCRIPTION,    SELECT A.EXPLODED_OFFERS
AS OFFERID,     SUM(VOLUME)TICKET_ID AS REDEMPTIONTICKET_VOLUMEID

  FROM    FROM OFFER_REDEMPTION_TRXNS A
  GROUP BY
    1,STG.DERIVED_MASTER_TABLE_NEW

      WHERE PARTITION_DATE_KEY BETWEEN 20230101 AND 20230731
      AND 2,COUNTRY_NM = 'CANADA'
  3 ) SELECT  AND a.WEEKIS_STARTPASS_DTTHROUGH AS= WKDT,0 
 OFFER_DESCRIPTION,   OFFERID,  AND SUMLEFT(REDEMPTION_VOLUMEREGISTERED_ACCOUNT_ID,7) FROM= 'us-east'
 REDEMPTION_SUMMARY A  )
GROUP
BY 1,2,3

Used to track the volume of redemptions for each offer in a given week.

Offer Challenge

Code Block
languagesql
with TRXN_OFFER_CHALLENGES_REDEMPTIONS as (SELECT
    A.*

WITH EXPLODED AS ( FROM TENDERS A

    SELECTINNER JOIN LOYALTY B
    ON A.TICKET_ID = TH_FISCAL_YEAR,B.TICKET_ID
    )

SELECT
CASE
  TH_FISCAL_WEEK,        WHEN UPPER(TENDER_NAME) IN DATE_FORMAT(
            CAST(('CASH', 'COMPTANT', 'EFECTIVO', 'US CASH', 'CANADIAN CASH', 'CDN CASH', 'ROUNDED CASH', 'ROUNDED COMPTANT') THEN 'CASH'

          WHEN UPPER(TENDER_NAME) IN UNIX_TIMESTAMP(LEFT(WEEK_START_DT, 10)('DEBIT CARD', 'yyyy-MM-dd') AS TIMESTAMP
        DEBIT', 'CARTE DEBIT', 'DEBITO', 'DÉBIT', 'DO DEBIT') THEN 'DEBIT'

  ),        WHEN UPPER(TENDER_NAME) IN  ('VISA', 'yyyyMMddMASTERCARD', 'MASTER CARD', 'AMEX', 'AMERICAN EXPRESS', 'CREDIT CARD', 'CREDIT CARDS',  ) AS WEEK_START_MAPPING,
          CAST(PERIOD_DT AS DATE) AS PERIOD_DT,
     'DISCOVER', 'M/C', 'DISCOVER CARD', 'DIGITAL AMEX', 'DIGITAL DISCOVER', 'DIGITAL MASTER CARD', 'DIGITAL MASTERCARD', 'DIGITAL AMERICAN EXPRESS', 'DIGITAL VISA', 'DO VISA', 'DO MASTERCARD') THEN 'CREDIT'

   REGISTEREDACCOUNTID,       WHEN UPPER(TENDER_NAME) IN ('TIM loyaltyCustomerIdCARD', 'DIGITAL TIM CARD', 'CARTE TIM', 'MOBILE TIM CARD', 'DIGITAL CARTE TRANSACTIONIDTIM', 'TIM CARTE', 'TIMS GIFT CARD', 'DIGITAL TIMS GIFT CARD',  EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS,
    'CARTE-CADEAU TIM', 'DIGITAL CARTE-CADEAU TIM') THEN 'TIMCARD'

    REST_TYP_NM,      WHEN UPPER(TENDER_NAME) LIKE '%SKIP%'  OPS_DIV_NMTHEN 'SKIP'

       FROM   WHEN UPPER(TENDER_NAME) LIKE '%UBER%' THEN 'UBER'

 PRODRT.CURATED_TRANS_EVENTS_NEW -- 1.	Challenge duration: 26/09 to 02/10    WHEN UPPER(TENDER_NAME) LIKE '%DOOR%' THEN WHERE'DOORDASH'

         DATE_KEY BETWEEN '${myapplication.Offer_Start_Date}'
          AND '${myapplication.Offer_End_Date}'
          AND COUNTRY_NM = 'CANADA'
          AND REGISTEREDACCOUNTID IS NOT NULL
          AND TRANSACTIONID IS NOT NULL -- AND REST_TYP_NM = "STANDARD"
      )
      SELECT
        DISTINCT A.TH_FISCAL_YEAR,WHEN UPPER(TENDER_NAME) IN ('SCAN AND PAY VISA', 'SCAN AND PAY MASTERCARD', 'SCAN AND PAY TIMCARD', 'SCAN AND PAY AMEX', 'SCAN AND PAY DISCOVER', 'SCAN AND PAY TIM CARD', 'NUMERISEZ ET PAYEZ – VISA', 'SCANTOPAY', 'NUMERISEZ ET PAYEZ – MASTERCARD', 'NUMERISEZ ET PAYEZ – CARTE TIM', 'NUMÉRISEZ ET PAYEZ – VISA', 'NUMÉRISEZ ET PAYEZ – MASTERCARD', 'NUMÉRISEZ ET PAYEZ – CARTE TIM', 'NUMERISEZ ET PAYEZ – AMEX', 'NUMÉRISEZ ET PAYEZ – AMEX', 'SCAN AND PAY TIMS GIFT CARD', 'NUMERISEZ ET PAYEZ CARTE-CADEAU TIM') THEN 'SCANANDPAY'

           A.TH_FISCAL_WEEK,
        A.WEEK_START_MAPPING,
        A.PERIOD_DT,
        A.REGISTEREDACCOUNTID,
        A.loyaltyCustomerId,
        A.TRANSACTIONID,
        A.REST_TYP_NM,
        A.OPS_DIV_NM,
        B.DESCRIPTION,
  WHEN UPPER(TENDER_NAME) IN ('HST', 'HST1', 'TVQ', 'TPS', 'GST', 'TAX', 'PST', 'HST TAXABLE SALES', 'SALES TAX' 'HST 1', 'H.S.T.1', 'H.S.T', 'HST 13% TAXABLE SALES', 'GST TAXABLE SALES', 'TAX 1', 'HST 1', 'GST# 75696 6891 RT0001', 'HST # 897258141', 'HST5%', 'HST8%', 'QST', 'SALES TAX', 'MEAL PLAN CARD - PREPAID TAX', 'CARTE PLAN REPAS - TAX PREPAYEE', 'GST # 121071781RT0001', 'TVH', 'TVH1', 'VAF', 'H.S.T.') THEN 'TAX'

    1 AS REDEMPTIONS    WHEN ((UPPER(TENDER_NAME) LIKE FROM'%ROUND%') OR (UPPER(TENDER_NAME) LIKE '%ARRONDIS %')) THEN 'ROUND UP'
EXPLODED
AS A         LEFTELSE JOIN DYDB.OFFERS'OTHER'
END AS B ON A.EXPLODED_OFFERS = B.OFFERID
      WHERE
   TENDER,
COUNT(DISTINCT TICKET_ID) AS TRXNS

FROM LOYALTY_TENDERS

GROUP BY 1

Total sales $ and ticket count organized by tender type (debit, credit, cash, Tims Card, tax) for a given restaurant

Discounting

Code Block
languagesql
  With base as(
    EXPLODED_OFFERSselect
= '76290e2e-1783-442f-8ff6-a2b16900a34e'     ),TH_FISCAL_YEAR,
      pointsperiod_issueddt,
 as (    state_nm,
  Select    detail_type,
    *,  ops_div_nm,
      WEEKOFYEAR(to_date(partition_date_ticket_details_key, "yyyyMMdd")) AS WEEK_START
      ticket_details_pos_no,
      a.ticket_details_pos_nm,
 regexp_extract(barcode, '(\\d+)|(\\d+)', 0) as lid     B.discount_key,
      FromB.discount_cd,
        prodrtB.curated_points_events as pointsdiscount_nm,
      C.coupon_key,
  where    C.coupon_cd,
    partition_date_key BETWEEN '${myapplication.Offer_Start_Date}'C.coupon_offr_nm,
      D.Category,
  AND '${myapplication.Offer_End_Date}'   SUM(amount) as amt,
   and tag = 'PRODUCT_CHALLENGED_COMPLETED' count(distinct(ticket_id)) as TRXNS
    from
),     completed as(
 STG.DERIVED_MASTER_TABLE_NEW a
     Select left join loyalty.tlog.dim_discount b on    a.THticket_FISCALdetails_YEARkey as= TH_FISCAL_YEAR,b.discount_key
      left join tlog.dim_coupon c on a.THticket_FISCALdetails_WEEKkey as= TH_FISCAL_WEEK,c.coupon_key
      left join a.WEEK_START_MAPPING as WEEK_START_MAPPING,
        a.PERIOD_DT as PERIOD_DT,loyalty.analytics.clearview_mapping_discount_types d on a.ticket_details_pos_nm = d.ticket_details_pos_nm
    where
   DATE_FORMAT(   amount < 0
     CAST( and quantity > 0
      AND  UNIX_TIMESTAMP(LEFT(PERIOD_DT, 10), 'yyyy-MM-dd') AS TIMESTAMP
 COUNTRY_NM = 'CANADA' -- and rest_no = 100387
      -- and ),
 date_key >= 20240101
    GROUP BY
  'yyyyMMdd'    1,
    ) as transaction_dt2,
      3,
 a.REGISTEREDACCOUNTID as REGISTEREDACCOUNTID,   4,
     a.loyaltyCustomerId as loyaltyCustomerId 5,
      6,
 a.TRANSACTIONID as TRANSACTIONID,    7,
    a.REST_TYP_NM as REST_TYP_NM8,
      9,
 a.OPS_DIV_NM as OPS_DIV_NM,    10,
    a.DESCRIPTION as DESCRIPTION11,
      12,
 a.REDEMPTIONS as REDEMPTIONS,   13,
     b.transactionID as completion_transactionID 14,
        b.pointsEarned as pointsEarned,
        b.restaurant as restaurant,
        b.partition_date_key as offer_completion_dt,
        b.WEEK_START as offer_completion_week,
        b.lid as lid
      from
        TRXN_OFFER_CHALLENGES_REDEMPTIONS a
        left join points_issued b on a.loyaltyCustomerId = b.lid
        and b.WEEK_START = a.TH_FISCAL_WEEK
    )
    Select
      TH_FISCAL_YEAR,
      TH_FISCAL_WEEK,
      WEEK_START_MAPPING,
      REGISTEREDACCOUNTID,
      loyaltyCustomerId,
      offer_completion_week,
      count(
        distinct(
          case
            when offer_completion_dt is not NULL
            and transaction_dt <= offer_completion_dt then TRANSACTIONID
          end
        )
      ) as trnx_before_completion,
      count(distinct(TRANSACTIONID)) as total_trnx,
      count(
        distinct (
          case
            when lid is not Null then lid
          end
        )
      ) as completed
    from
      completed
    group by 1, 2, 3, 4, 5, 6

Count of guests who completed a specific Offer Challenge

Games

NHL Hockey Challenge & Tims Word Challenge

Code Block
languagesql
SELECT    YEAR(TIMESTAMP) AS YR
          , MONTH(TIMESTAMP) AS MTH 
          , COUNT(DISTINCT GUESTS) AS GUESTS FROM (
-- WORD CHALLENEGE PLAYERS

SELECT    DISTINCT TIMESTAMP, _TIMHORTONS.LOYALTY.ID AS GUESTS
FROM  15
Code Block
loyalty.analytics.clearview_mapping_discount_types

This table is manually mapped by grouping ticket_detail_POS_nm into categories

Combo Discount, Combo Discount (BG Bundle), Tims Rewards, Targeted Offers, Campaign, In-restaurant, Other, Settlement, and Uncategorized

This mapping was last updated in March 2024; any unmapped fields would show up as null and would be considered as “Other”

Discounts on offerids

Code Block
languagesql
-- Total Summary
with clean_loyalty_transactions as(
  with FILTERED as(
    WITH SEPERATED AS (
      -- Filter for Exploded offers for offer ids and explode the disc amt with corresponding PLU
      with zipped as (
        -- explode offers and combine the Discount amount with offer
        SELECT
          *,
          arrays_zip(discountAmounts, appliedOffers) as comb --   EXPLODE(APPLIEDOFFERS) AS EXPLODED_OFFERS
        FROM
          PRODRT.CURATED_TRANS_EVENTS_NEW
        WHERE
          partition_date_key >= 20201201
          -- to_date(partition_date_key, "yyyyMMdd") BETWEEN DATE '$Start_Date' AND DATE '$End_Date'
          AND LEFT(REGISTEREDACCOUNTID, 7) = 'us-east'
          AND APPLIEDOFFERS IS NOT NULL
          AND COUNTRY_NM = 'CANADA'
      )
      select
        DISTINCT transactionId,
        loyaltyCustomerId,
        registeredAccountId,
        state_nm,
        ticketId,
        period_dt,
        th_fiscal_week,
        th_fiscal_year,
        week_start_dt,
        explode(Comb) as test
      from
        zipped
    )
    SELECT
      *,
      test ['discountAmounts'] AS DISC_AMT,
      test ['appliedOffers'] AS APPLIED_OFFER
    FROM
      SEPERATED
  )
  select
    FILTERED.*,
    O.NAME,
    O.DESCRIPTION,
    1 as VOLUME
  From
    FILTERED
    inner JOIN DYDB.OFFERS O ON O.OFFERID = FILTERED.APPLIED_OFFER
)
SELECT
  TH_FISCAL_YEAR,
  th_fiscal_week,
  date(week_start_dt) as wk_start_dt,
  state_nm, 
  APPLIED_OFFER,
  DESCRIPTION,
  SUM(DISC_AMT) AS DISCOUNT_DOLLARS,
  SUM(VOLUME) AS REDEMPTION_VOLUME
FROM
  clean_loyalty_transactions
GROUP BY
  1,2,3,4,5,6

Tims Word Challenge Player Levels

Code Block
languagesql
SELECT LEVEL, COUNT(DISTINCT ID) AS USERS
FROM (
SELECT    _TIMHORTONS.LOYALTY.ID, MAX(DATE(TIMESTAMP)) AS DTE
        , COALESCE(MAX(CAST(SUBSTRING(_TIMHORTONS.INTERACTION.ELEMENT.VALUE,18,CHARINDEX('-',REPLACE(_TIMHORTONS.INTERACTION.ELEMENT.VALUE,'"','-'),18)-18) AS INT)),0) LEVEL
FROM    loyalty.events.adobe_app_events
WHERE   EVENTTYPE 
WHERE= 'element_clicked'
AND     TRIM(DATE(TIMESTAMP) >= DATE '2023-11-01'
AND     _TIMHORTONS.INTERACTION.PATH) IN= ('/timswordchallenge')
AND       TRIM(_TIMHORTONS.INTERACTION.ELEMENT.NAME) = 'play'
AND       _TIMHORTONS.LOYALTY.PLATFORMID IN ('app')
AND       LEFT(_TIMHORTONS.LOYALTY.ID,7) = 'us-east'
AND       DATE >= DATE '2023-11-01' 

UNION
-- HOCKEY PLAYERS

SELECT    DISTINCT TIMESTAMP,_TIMHORTONS.LOYALTY.ID  AS GUESTS
FROMSELECT DISTINCT registeredAccountId FROM loyalty.users.customer_base WHERE LEFT(loyaltyCustomerId,4) IN ('0463','0473'))
GROUP BY 1
)
GROUP BY 1
ORDER BY 1

Points Issued by Channel

Code Block
languagesql
WITH OFFER_BASE AS
(
          loyalty.events.adobe_app_events WHERE SELECT 
  TRIM(_TIMHORTONS.INTERACTION.PATH) = '/hockey_challenge' AND       TRIM(_TIMHORTONS.INTERACTION.ELEMENT.NAME) IN ('submit_picks')
ANDMONTH_DT,
        _TIMHORTONS.PLATFORM IN ('app') AND SUM(CASE WHEN A.TAG IS NULL AND LEFT(_TIMHORTONSA.LOYALTYEXPLODED.IDOFFERID,711) = 'us-eastEARN_POINTS' AND       DATE >= DATE '2023-11-01' 
)
GROUP BY 1,2
ORDER BY 1 DESC, 2

Count of guests who played Games (NHL Hockey Challenge and Tims Word Challenge).

Limitation: Data only available from Nov 1, 2023.

Total Sales and Ticket Count by Tender Type

Code Block
languagesql
WITH LOYALTY_TENDERS AS
(
    WITH TENDERS AS
    (THEN A.EXPLODED.TIMSPOINTSEARNED ELSE 0 END) AS BASE,
            SUM(CASE WHEN LEFT(A.EXPLODED.OFFERID,11) <> 'EARN_POINTS' AND A.EXPLODED.OFFERID IS NOT NULL AND A.TAG IS NULL THEN A.EXPLODED.TIMSPOINTSEARNED ELSE 0 END) AS OFFERS
          SELECT  

   REPLACE(UPPER(TRIM(TENDER_NAME)), '.', '') AS TENDER_NAME,     FROM (SELECT TICKET_ID
       FROM loyalty.tlog.tlog_sale_ticket_tenders          WHERE  LAST_DAY(TO_DATE(PARTITION_DATE_KEY BETWEEN 20230101 AND 20230731, 'yyyyMMdd')) AS MONTH_DT,
          AND LEFT(REST_NO,2) = 10     )TAG,
     LOYALTY AS     (       SELECTTRANSACTIONID,
       TICKET_ID AS TICKET_ID        FROM STG.DERIVED_MASTER_TABLE_NEW
 POINTSEARNED,
      WHERE PARTITION_DATE_KEY BETWEEN 20230101 AND 20230731       AND COUNTRY_NM = 'CANADA'
      AND IS_PASS_THROUGH = 0coalesce(cast(isCustomerServiceVisit as string), '') as ISCUSTOMERSERVICEVISIT,
          AND LEFT(REGISTERED_ACCOUNT_ID,7) = 'us-east'     EXPLODE(APPLIEDOFFERDETAILS) AS EXPLODED
    SELECT     A.*   
  FROM TENDERS A      INNER JOIN LOYALTY B     ONFROM APRODRT.TICKETCURATED_POINTS_IDEVENTS =A
B.TICKET_ID
    )  SELECT CASE           WHENWHERE UPPER(TENDER_NAME) IN ('CASH', 'COMPTANT', 'EFECTIVO', 'US CASH', 'CANADIAN CASH', 'CDN CASH', 'ROUNDED CASH', 'ROUNDED COMPTANT') THEN 'CASH'

TO_DATE(PARTITION_DATE_KEY, 'yyyyMMdd') BETWEEN DATE '2024-05-01' AND DATE '2024-05-31' --UPDATE THIS
         WHEN UPPER(TENDER_NAME) IN ('DEBIT CARD', 'DEBIT', 'CARTE DEBIT', 'DEBITO', 'DÉBIT', 'DO DEBIT') THEN 'DEBIT'

            AND LEFT(BARCODE, 4) = '0463'
      WHEN UPPER(TENDER_NAME) IN ('VISA', 'MASTERCARD', 'MASTER CARD', 'AMEX', 'AMERICAN EXPRESS', 'CREDIT CARD', 'CREDIT CARDS'AND COALESCE(PARTNERID, 'DISCOVER', 'M/C',) = 'DISCOVER CARD', 'DIGITAL
AMEX', 'DIGITAL DISCOVER', 'DIGITAL MASTER CARD', 'DIGITAL MASTERCARD', 'DIGITAL AMERICAN EXPRESS', 'DIGITAL VISA', 'DO VISA', 'DO MASTERCARD') THEN 'CREDIT'AND ISCUSTOMERSERVICEVISIT IS NOT TRUE
       WHEN UPPER(TENDER_NAME) IN ('TIM CARD', 'DIGITAL TIM CARD', 'CARTE TIM', 'MOBILE TIM) CARD',A
'DIGITAL
CARTE TIM', 'TIM CARTE', 'TIMS GIFT CARD', 'DIGITAL TIMS GIFT CARD', 'CARTE-CADEAU TIM', 'DIGITAL CARTE-CADEAU TIM') THEN 'TIMCARD'

 GROUP BY 1
),

ALL_OTHER AS
(
         WHEN UPPER(TENDER_NAME) LIKE '%SKIP%'SELECT THEN
'SKIP'            WHEN UPPER(TENDER_NAME) LIKE '%UBER%' THEN 'UBER'LAST_DAY(TO_DATE(PARTITION_DATE_KEY, 'yyyyMMdd')) AS MONTH_DT,
            SUM(CASE WHEN B.TAG IN UPPER(TENDER_NAME) LIKE '%DOOR%' THEN 'DOORDASH'('DAYPART_CHALLENGED_COMPLETED','PRODUCT_CHALLENGED_COMPLETED','FREQUENCY_CHALLENGED_COMPLETED') THEN B.POINTSEARNED ELSE 0 END) AS CHALLENGES,
            SUM(CASE WHEN UPPER(TENDER_NAMELEFT(TAG, 4) IN= ('RUTR'SCAN ANDTHEN PAYPOINTSEARNED VISA', 'SCAN AND PAY MASTERCARD', 'SCAN AND PAY TIMCARD', 'SCAN AND PAY AMEX', 'SCAN AND PAY DISCOVER', 'SCAN AND PAY TIM CARD', 'NUMERISEZ ET PAYEZ – VISA', 'SCANTOPAY', 'NUMERISEZ ET PAYEZ – MASTERCARD', 'NUMERISEZ ET PAYEZ – CARTE TIM', 'NUMÉRISEZ ET PAYEZ – VISA', 'NUMÉRISEZ ET PAYEZ – MASTERCARD', 'NUMÉRISEZ ET PAYEZ – CARTE TIM', 'NUMERISEZ ET PAYEZ – AMEX', 'NUMÉRISEZ ET PAYEZ – AMEX', 'SCAN AND PAY TIMS GIFT CARD') THEN 'SCANANDPAY'ELSE 0 END) AS RUTW,
            SUM(CASE WHEN LEFT(B.TAG, 6) = 'HOCKEY' THEN B.POINTSEARNED ELSE 0 END) AS HOCKEY,
            SUM(CASE WHEN B.ISCUSTOMERSERVICEVISIT = 'true' THEN B.POINTSEARNED ELSE 0 END) AS GUEST_CARE,
            SUM(CASE WHEN UPPER(B.TAG) = 'WORD_CHALLENGE_LEVEL' THEN B.POINTSEARNED ELSE 0 END) AS WORD_CHALLENGE,
           WHEN UPPER(TENDER_NAMESUM(B.POINTSEARNED) IN ('HST', 'HST1', 'TVQ', 'TPS', 'GST', 'TAX', 'PST', 'HST TAXABLE SALES', 'SALES TAX' 'HST 1', 'H.S.T.1', 'H.S.T', 'HST 13% TAXABLE SALES', 'GST TAXABLE SALES', 'TAX 1', 'HST 1', 'GST# 75696 6891 RT0001', 'HST # 897258141', 'HST5%', 'HST8%', 'QST', 'SALES TAX', 'MEAL PLAN CARD - PREPAID TAX', 'CARTE PLAN REPAS - TAX PREPAYEE', 'GST # 121071781RT0001', 'TVH', 'TVH1', 'VAF', 'H.S.T.') THEN 'TAX'AS TOTAL_POINTS

            FROM PRODRT.CURATED_POINTS_EVENTS B

            WHERE TO_DATE(PARTITION_DATE_KEY, 'yyyyMMdd') BETWEEN DATE '2024-05-01' AND DATE '2024-05-31' --UPDATE THIS
            AND LEFT(BARCODE, 4) = '0463'
            WHENAND ((UPPER(TENDER_NAMECOALESCE(PARTNERID, '') LIKE= '%ROUND%') 

OR (UPPER(TENDER_NAME) LIKE '%ARRONDIS %')) THEN 'ROUND UP'     GROUP BY 1
)

SELECT 
ELSE 'OTHER'
END AS TENDER,
COUNT(DISTINCT TICKET_ID) AS TRXNS

FROM LOYALTY_TENDERS

GROUP BY 1
Total sales $ and ticket count organized by tender type (debit, credit, cash, Tims Card, tax) for a given restaurant
A.MONTH_DT,
BASE,
OFFERS,
CHALLENGES,
RUTW,
HOCKEY,
GUEST_CARE,
WORD_CHALLENGE,
TOTAL_POINTS

FROM OFFER_BASE A 

LEFT JOIN ALL_OTHER B
ON A.MONTH_DT = B.MONTH_DT