SPUR GROUP PTY DATA WAREHOUSE LOAD FACTS & AGGREGATE

June 23, 2010

PREPARED BY: Sedick Isaacs Winslow Momberg In Duminy SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

TABLE OF CONTENTS

INTRODUCTION...... 4

OBJECTIVES OF DOCUMENT...... 4

1 UPDATE DWH FACTS...... 5

1.1 UPDATE DIMENSION WAITER...... 5 1.2 UPDATE DIMENSION SUPPLIER...... 6 1.3 UPDATE DIMENSION PRODUCT...... 6 1.4 UPDATE FACTSALE_1111111...... 7 1.5 UPDATE FACTSALEMODIFIER_1111111...... 7 1.6 UPDATE FACTSALESETMENU_1111111...... 8 1.7 UPDATE FACTLOYALTY_1111...... 9 1.8 UPDATE FACTPURCHASE_1111...... 9 2 UPDATE ISSUMMARISED...... 10

3 UPDATE AGGREGATES...... 11

3.1 UPDATE FACTTRADINGSTORE_11...... 12 3.2 UPDATEFACTTRADINGSTORE_36...... 12 3.3 UPDATEFACTSALE_1110011...... 13 3.4 UPDATEFACTSALE_1116111...... 13 3.5 UPDATE FACTSALE_1011100...... 14 3.6 UPDATEFACTSALE_1001100_AVERAGE...... 14 3.7 UPDATEFACTSALE_1011100_AVERAGE...... 15 3.8 UPDATEFACTSALE_1010000...... 15 3.9 UPDATEFACTSALE_3001100_AVERAGE...... 16 3.10 UPDATEFACTSALE_3006100_AVERAGE...... 16 3.11 UPDATEFACTSALE_3011100...... 17 3.12 UPDATEFACTSALE_3010000...... 18 3.13 UPDATEFACTSTOREOPERATION_31...... 19 3.14 UPDATEFACTSALE_4001100_AVERAGE...... 19 3.15 UPDATEFACTSALE_4006100_AVERAGE...... 20 3.16 UPDATEFACTSALE_2001100_AVERAGE...... 20 3.17 UPDATEFACTSALE_2006100_AVERAGE...... 21 4 UPDATE CONTROL TABLES...... 22

A. APPENDIX – FACTS & AGGREGATE TABLE(S)...... 23

1. FACTSALE_1111111...... 23

2. FACTSALEMODIFIER_1111111...... 24

3. FACTSALESETMENU_1111111...... 25

4. FACTPURCHASE_1111...... 26

5. FACTTRADINGSTORE_11...... 26

6. FACTTRADINGSTORE_36...... 27

7. FACTSALE_1110011...... 27

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 2 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

8. FACTSALE_1116111...... 28

9. FACTSALE_1011100...... 29

10. FACTSALE_1001100...... 30

11. FACTSALE_1010000...... 31

12. FACTSALE_3001100...... 31

13. FACTSALE_3011100...... 32

14. FACTSALE_3010000...... 32

15. FACTSALE_3006100...... 33

16. FACTSALE_4001100...... 34

17. FACTSALE_4006100...... 35

18. FACTSTOREOPERATION_31...... 35

19. ID_[SITE]_CONTROL...... 36

20. ID_[SITE]_CONTROL...... 36

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 3 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

Introduction This document outlines the load facts and aggregate process that occurs on the data warehouse staging server.

Objectives of Document The objectives of this document are for Spur IT development: 1. To provide management and developers a reference document when needing to understand the process. 2. To highlight known issues and limitations. 3. To assist with project management.

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 4 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

1 Update DWH Facts The purpose of this process is to load sales and purchasing data from the staging database into the data warehouse. It also updates the staging database indicating which records have been loaded. The waiter,supplier and product dimensions are loaded as part of this step, because the DWH framework processes data by site.

Add the following steps to the framework:

StepID StepName Command IsActive 1 Update DimWaiter Exec UpdateDimWaiter 1 2 Update DimSupplier Exec UpdateDimSupplier 1 3 Update FactSale_1111111 Exec UpdateFactSale_1111111 1 4 Update DimProduct Exec UpdateDimProduct 1 5 Update FactSaleModifier_1111111 Exec UpdateFactSaleModifier_1111111 1 6 Update FactSaleSetMenuItem_1111111 Exec UpdateFactSaleSetMenuItem_1111111 1 7 Update FactLoyalty_1111 Exec UpdateFactLoyalty_1111 0 8 Update FactPurchase_1111 Exec UpdateFactPurchase_1111 1

How to run this step?:

1. SubmitJobs ‘Update DWH Facts’ 2. ExecuteJobs ‘Update DWH Facts’

Known Issues & Limitations: 1. The loading into factsale, factsalemodifier and factsalesetmenu is dependent on the itemtype being updated. 2. Updating the staging database, setting records as loaded, for set menu items is taking very long. 3. Waiter are loaded as “Not Assigned” when no waiter is found – this applies mostly for historical data, as the store might delete waiter information. 4. Loyalty data was loaded before, but it ONLY reflects monetary transactions i.e. birthday voucher etc. Swipes are not reflected.

1.1 Update Dimension Waiter This step updates the waiter dimension with new waiter info and updates existing waiters.

Set @Sql = 'INSERT INTO DimWaiter (WaiterId, IdNo, SiteId, Firstname, Surname, TelNo, Address, Section, Status, isDeleted, DateCreated, DateUpdated, UpdatedBy) SELECT Distinct IsNull(CasId,'''') As WaiterId, IsNull(IdNo,'''') As IdNo, IsNull(Site,'''') As SiteId, IsNull([Name],'''') as FirstName, IsNull(Surname,'''') as Surname, IsNull(Tel,'''') As TelNo, IsNull(Address,'''') As Address, IsNull(Section,'''') As Section, IsNull(Status,'''') As Status, 0, Getdate() As DateCreated, Getdate() As DateUpdated, ''UpdateDimWaiter'' As UpdatedBy FROM Chewbacca.Staging_Spur.Live.Waiter_' + @Site + ' a WHERE NOT EXISTS ( SELECT WaiterKey FROM DimWaiter b

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 5 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

WHERE b.WaiterId = a.CasId AND b.SiteId = a.Site AND a.[Name] = b.FirstName AND a.Surname = b.Surname )'

Exec (@Sql)

If Exists (Select SiteId, WaiterId FRom DimWaiter Where isDeleted = 0 Group By SiteId, WaiterId Having COUNT(*) > 1) Begin -- Set isDeleted Update DimWaiter Set isDeleted = 0, DateUpdated = GETDATE()

Update DimWaiter Set isDeleted = 1, DateUpdated = GETDATE() Where WaiterKey In ( Select WaiterKey From DimWaiter a Inner Join ( Select SiteId, WaiterId From DimWaiter Group By SiteId, WaiterId Having COUNT(*) > 1 ) b on a.SiteId = b.SiteId And a.WaiterId = b.WaiterId ) And WaiterKey Not In ( Select MIN(WaiterKey) From DimWaiter Group By SiteId, WaiterId Having COUNT(*) > 1 ) End

1.2 Update Dimension Supplier Supplier dimension is updated with new supplier entries. set @sql = 'Insert Into DimSupplier(SupplierAlternateKey, SiteId, SupplierName, BrandName, isDeleted, EventDetailLogId, DateCreated, DateUpdated) Select Distinct Supp As SupplierAlternateKey, Site, Supplier As SupplierName, ''Spur'', 0 As isDeleted, ' + convert(varchar(10),@EventLogDetailID) + ' As EventDetailLogId, GetDate() As DateCreated, GetDate() As DateUpdated From Chewbacca.Staging_Spur.Live.Purchase_' + @Site + ' a Where Not Exists (Select Supp From DimSupplier b Where b.SupplierName = a.Supplier And b.isDeleted = 0)'

Exec (@sql)

1.3 Update Dimension Product New product entries added to the product dimension. set @sql = 'Insert Into DimProduct(ProductAlternateKey, ProductName, Category, BrandName, isDeleted, EventDetailLogId, DateCreated, DateUpdated, UpdatedBy) Select Distinct Prod As ProductAlternateKey, a.Item, Cat, ''Spur, 0 As IsDeleted,' + convert(varchar(10),@EventLogDetailId) + ' As EventDetailLogId, GetDate() As DateCreated, GetDate() As DateUpdated, ''UpdateDimProduct'' As UpdatedBy From Chewbacca.Staging_Spur.Live.Purchase_' + @Site + ' a Where Not Exists (Select ProductKey From DimProduct b Where a.Item = b.ProductName And b.isDeleted = 0)'

Exec (@sql)

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 6 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

1.4 Update FactSale_1111111 Loads the lowest sales level.

Set @SQL = 'Insert Into FactSale_1111111(DateKey, TimeKey, StoreKey, ItemKey, PromotionKey, WaiterKey, OUTM, Quantity, [Value], SellingPrice, CostPrice, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, TotalCost, RedeemValue, TicketClaim, CustomerTip, TransactionType, OrderType, TableNo, Station, Split, ItemCount, CustomerCount, [FileName], StagingID, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select DateKey, g.TimeKey, d.StoreKey, e.ItemKey, 0 As PromotionKey, IsNull(f.WaiterKey, -1) As WaiterKey, b.OUTM, b.QTY As Quantity, b.[Value] - b.Tax As [Value], b.Price As SellingPrice, 0 As CostPrice, a.Discnt As TotalDiscnt, a.Amount As BillAmount, a.BDiscnt As BillDiscount, a.Tax as BillTax, b.Tax As ItemTax, IsNull(b.Discnt,0) As LineDiscount, a.Cost, IsNull(a.Redeem,0) As RedeeemValue, IsNull(a.Tktclaim,0) As TicketClaim, a.CTIP As CustomerTip, a.PType As TransactionType, a.OrdType As OrderType, a.[Table] As TableNo, a.Station, b.Split, a.ICNT, a.Cust, a.[FileName], b.StagingID, ' + convert(varchar(10), @EventLogDetailId) + ', 0 As IsSummarised, getdate() As DateCreated, getdate() As DateUpdated From Chewbacca.Staging_Spur.Live.IM_' + @Site + ' a INNER JOIN Chewbacca.Staging_Spur.Live.ID_' + @Site + ' b ON a.OUTM = b.OUTM AND a.RecordMonth = b.RecordMonth INNER JOIN Chewbacca.Staging_Spur.dbo.AuditType IMAuditType On a.AuditTypeId = IMAuditType.AuditTypeId And IMAuditType.isDiscarded=0 INNER JOIN Chewbacca.Staging_Spur.dbo.AuditType IDAuditType On b.AuditTypeId = IDAuditType.AuditTypeId And IDAuditType.isDiscarded=0 INNER JOIN DimDate c ON a.IDate = c.CalendarDay INNER JOIN DimStore d ON a.Site = d.Siteid And d.SiteId = ''' + @Site + ''' INNER JOIN DimItem e ON b.PLU = e.PLUCode AND e.isDeleted = 0 And e.ItemType = ''Item'' LEFT OUTER JOIN DimWaiter f On a.Site = f.SiteId And a.CasId = f.WaiterId And f.WaiterId <> 0 And f.isDeleted = 0 Inner Join DimTimeDayPart g on convert(varchar(10),a.TYME) Between g.StartTimeOfDay And g.EndTimeOfDay WHERE d.LockedDownDate <= c.CalendarDay AND NOT EXISTS ( SELECT DateKey FROM FactSale_1111111 fct WHERE fct.DateKey = c.DateKey AND fct.StoreKey = d.StoreKey )' Exec (@SQL)

1.5 Update FactSaleModifier_1111111 Loads the lowest sales modifier level.

SET @SQL = 'Insert Into FactSaleModifier_1111111(DateKey, TimeKey, StoreKey, ItemKey, PromotionKey, WaiterKey, OUTM, Quantity, [Value], TotalCost, SellingPrice, CostPrice, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, CustomerTip,

TransactionType, OrderType, TableNo, Station, Split, ItemCount, CustomerCount, [FileName], StagingID, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select DateKey, g.TimeKey, d.StoreKey, e.ItemKey, 0 As PromotionKey, IsNull(f.WaiterKey, -1) As WaiterKey, b.OUTM, b.QTY As Quantity, b.[Value], a.Cost, b.Price As SellingPrice, 0 As CostPrice, a.Discnt As TotalDiscnt, a.Amount As BillAmount, a.BDiscnt As BillDiscount, a.Tax as BillTax, b.Tax As ItemTax, IsNull(b.Discnt,0) As LineDiscount, IsNull(a.Redeem,0) As RedeeemValue, IsNull(a.Tktclaim,0) As TicketClaim, a.CTIP As CustomerTip, a.PType As TransactionType, a.OrdType As OrderType, a.[Table] As TableNo, a.Station, b.Split, ICNT as ItemCount, CUST as CustomerCount, a.[FileName], a.StagingID,' + convert(varchar(10), @EventLogDetailId) + ', 0 As IsSummarised, getdate() As DateCreated, getdate() As DateUpdated From Chewbacca.Staging_Spur.Live.IM_' + @Site + ' a INNER JOIN Chewbacca.Staging_Spur.Live.ID_' + @Site + ' b ON a.OUTM = b.OUTM AND a.RecordMonth = b.RecordMonth

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 7 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

INNER JOIN Chewbacca.Staging_Spur.dbo.AuditType IMAuditType On a.AuditTypeId = IMAuditType.AuditTypeId And IMAuditType.isDiscarded=0 INNER JOIN Chewbacca.Staging_Spur.dbo.AuditType IDAuditType On b.AuditTypeId = IDAuditType.AuditTypeId And IDAuditType.isDiscarded=0 INNER JOIN DimDate c ON a.IDate = c.CalendarDay INNER JOIN DimStore d ON a.Site = d.Siteid And d.SiteId = ''' + @Site + ''' INNER JOIN DimItem e ON b.PLU = e.PLUCode AND e.ItemType In (''Modifier'', ''Option'') LEFT OUTER JOIN DimWaiter f On a.Site = f.SiteId And a.CasId = f.WaiterId And f.WaiterId <> 0 And f.isDeleted = 0 Inner Join DimTimeDayPart g on convert(varchar(10),a.TYME) Between g.StartTimeOfDay And g.EndTimeOfDay WHERE d.LockedDownDate < c.CalendarDay AND NOT EXISTS ( SELECT DateKey FROM FactSaleModifier_1111111 fct WHERE fct.DateKey = c.DateKey AND fct.StoreKey = d.StoreKey )'

Exec (@SQL)

1.6 Update FactSaleSetMenu_1111111 Loads the lowest sales set menu level.

Set @SQL = 'Insert Into FactSaleSetMenuItem_1111111(DateKey, TimeKey, StoreKey, ItemKey, PromotionKey, WaiterKey, OUTM, Quantity, [Value], TotalCost, SellingPrice, CostPrice, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, CustomerTip, TransactionType, OrderType, TableNo, Station, Split, StagingID, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select DateKey, g.TimeKey, d.StoreKey, e.ItemKey, 0 As PromotionKey, IsNull(f.WaiterKey, -1) As WaiterKey, b.OUTM, b.QTY As Quantity, b.[Value], a.Cost, b.Price As SellingPrice, 0 As CostPrice, a.Discnt As TotalDiscnt, a.Amount As BillAmount, a.BDiscnt As BillDiscount, a.Tax as BillTax, b.Tax As ItemTax, IsNull(b.Discnt,0) As LineDiscount, IsNull(a.Redeem,0) As RedeeemValue, IsNull(a.Tktclaim,0) As TicketClaim, a.CTIP As CustomerTip, a.PType As TransactionType, a.OrdType As OrderType, a.[Table] As TableNo, a.Station, b.Split, a.StagingID, ' + convert(varchar(10), @EventLogDetailId) + ', 0 As IsSummarised, getdate() As DateCreated, getdate() As DateUpdated From Chewbacca.Staging_Spur.Live.IM_' + @Site + ' a INNER JOIN Chewbacca.Staging_Spur.Live.ID_' + @Site + ' b ON a.OUTM = b.OUTM AND a.RecordMonth = b.RecordMonth INNER JOIN Chewbacca.Staging_Spur.dbo.AuditType IMAuditType On a.AuditTypeId = IMAuditType.AuditTypeId And IMAuditType.isDiscarded=0 INNER JOIN Chewbacca.Staging_Spur.dbo.AuditType IDAuditType On b.AuditTypeId = IDAuditType.AuditTypeId And IDAuditType.isDiscarded=0 INNER JOIN dimDate c ON a.IDate = c.CalendarDay INNER JOIN dimStore d ON a.site = d.Siteid And d.SiteId = ''' + @Site + ''' INNER JOIN dimItem e ON b.PLU = e.PLUCode And e.IsDeleted=0 AND e.ItemType = ''Menu_Item'' LEFT OUTER JOIN DimWaiter f On a.Site = f.SiteId And a.CasId = f.WaiterId And f.WaiterId <> 0 And f.isDeleted = 0 Inner Join DimTimeDayPart g on convert(varchar(10),a.TYME) Between g.StartTimeOfDay And g.EndTimeOfDay WHERE d.LockedDownDate <= c.CalendarDay AND NOT EXISTS ( SELECT DateKey FROM FactSaleSetMenuItem_1111111 fct WHERE fct.DateKey = c.DateKey AND fct.StoreKey = d.StoreKey )'

EXEC (@SQL)

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 8 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

1.7 Update FactLoyalty_1111 Loads the lowest loyalty level. Set @sql = 'Insert Into FactLoyalty_1111(c.DateKey, b.StoreKey, WaiterKey, OUTM, TransactionType, CardNo, Amount, Reference, TableNo, Manager, Info, DateCreated, DateUpdated) Select DateKey, StoreKey, IsNull(d.WaiterKey,-1), OUTM, TranType, CardNo, Amount, Ref, TableNo, Manager, Info, GetDate(), GetDate() From Staging_Spur.Live.Maxitran_' + @Site + ' a Inner Join DimStore b on b.SiteId = ' + @Site + ' Inner Join DimDate c on a.TDate = c.CalendarDay Left Outer Join DimWaiter d on a.Manager = d.WaiterId And d.StoreKey = b.StoreKey Where Not Exists (Select DateKey From FactLoyalty_1111 fl Where fl.DateKey = c.DateKey And fl.StoreKey = b.StoreKey And fl.WaiterKey = d.WaiterKey)'

Exec (@Sql)

1.8 Update FactPurchase_1111 Loads the lowest purchase level. set @sql = 'Insert Into FactPurchase_1111(DateKey, StoreKey, ProductKey, SupplierKey, Link, PaymentDate, ShipmentDate, Cost, Quantity, Price, Vat, UnitOfMeasure, StoreReference, PaymentReference, ExcludesFranchiseFee, [FileName], StagingID, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select b.DateKey, c.StoreKey, d.ProductKey, e.SupplierKey, a.Link, a.PDATE As PaymentDate, a.PostDate As ShipmentDate, a.Cost, a.QTY, a.Price, a.VAT, a.UNIT, a.SREF, a.PREF, a.EXCLRLTY As ExcludesFranchiseFee, a.[FileName], a.StagingID, ' + convert(varchar(10), @EventLogDetailId) + ' As EventDetailLogId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From Chewbacca.Staging_Spur.Live.Purchase_' + @Site + ' a Inner Join Chewbacca.Staging_Spur.dbo.AuditType AuditType On a.AuditTypeId = AuditType.AuditTypeId And AuditType.isDiscarded=0 Inner Join DimDate b on a.D = b.CalendarDay Inner Join DimStore c on a.Site = c.SiteId Inner Join DimProduct d on a.Prod = d.ProductAlternateKey And d.isDeleted = 0 Inner Join DimSupplier e on a.Supp = e.SupplierAlternateKey And e.isDeleted = 0 And Not Exists (Select DateKey From FactPurchase_1111 Where DateKey = b.DateKey And StoreKey = c.StoreKey And ProductKey = d.ProductKey And SupplierKey = e.SupplierKey)' Exec (@sql)

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 9 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

2 Update isSummarised The purpose of this process is to flag the records that have already been aggregated, in order to improve the effiency of future aggregations.

Add the following steps to the framework:

StepID StepName Command IsActive 1 Update_isSummarised_FactSale_1111111 Exec Update_isSummarised_FactSale_1111111 1 2 Update_isSummarised_FactSale_1110011 Exec Update_isSummarised_FactSale_1110011 1 3 Update_isSummarised_FactSale_1011100 Exec Update_isSummarised_FactSale_1011100 1 4 Update_isSummarised_FactSale_1001100 Exec Update_isSummarised_FactSale_1001100 1 5 Update_isSummarised_FactSale_1010000 Exec Update_isSummarised_FactSale_1010000 1 6 Update_isSummarised_FactSale_3001100 Exec Update_isSummarised_FactSale_3001100 1

How to run this step?:

1. SubmitJobs ‘Update isSummarised’ 2. ExecuteJobs ‘Update isSummarised

Known Issues & Limitations: 1. None

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 10 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3 Update Aggregates The purpose of this process is to summarise and aggregate the information in the fact tables.

Add the following step to the framework:

StepID StepName Command IsActive 1 Update FactTradingStore_11 Exec R2D2.DWH_Spur.dbo.UpdateFactTradingStore_11 1 2 UpdateFactTradingStore_36 Exec R2D2.DWH_Spur.dbo.UpdateFactTradingStore_36 1 3 Update FactSale_1110011 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_1110011 1 4 UpdateFactSale_1116111 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_1116111 1 5 Update FactSale_1011100 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_1011100 1 6 Update FactSale_1001100_Average Exec R2D2.DWH_Spur.dbo.UpdateFactSale_1001100_Average 1 7 Update FactSale_1011100 Average Exec R2D2.DWH_Spur.dbo.UpdateFactSale_1011100_Average 1 8 Update FactSale_1010000 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_1010000 1 9 UpdateFactSale_3001100_Average Exec R2D2.DWH_Spur.dbo.UpdateFactSale_3001100_Average 1 10 Update FactSale_3061000 Average Exec R2D2.DWH_Spur.dbo.UpdateFactSale_3006100_Average 1 11 UpdateFactSale_3011100 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_3011100 1 12 UpdateFactSale_3010000 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_3010000 1 13 Update FactStoreOperation_31 Exec R2D2.DWH_Spur.dbo.UpdateFactStoreOperation_31 1 14 UpdateFactSale_4001100 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_4001100_Average 1 15 UpdateFactSale_4006100 Exec R2D2.DWH_Spur.dbo.UpdateFactSale_4006100_Average 1 16 UpdateFactSale_2001100_Average Exec R2D2.DWH_Spur.dbo.UpdateFactSale_2001100_Average 1 17 UpdateFactSale_2006100_Average Exec R2D2.DWH_Spur.dbo.UpdateFactSale_2006100_Average 1

How to run this step?:

1. SubmitJobs ‘Update DWH Aggregates’ 2. ExecuteJobs ‘Update DWH Aggregates’

Dependencies 1. SMART – StoreTradingDay, Roy_Declarations, TradingStatus, TradingStatusType 2. Tables OperationInformation and Employee

Known Issues & Limitations: 1. None

Notes: 1. Not ALL aggregates have been build e.g. regional totals, invoice analysis 2.

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 11 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.1 Update FactTradingStore_11 Load trading store table (Day, Store)

Insert Into FactTradingStore_11(datekey, storekey, lockeddown, DateCreated, DateUpdated) Select datekey, storekey, case when a.day < lockeddowndate then 'No' else 'Yes' end as LockedDown, GetDate(), GetDate() From nilo.smart.dbo.storetradingday a Inner join DWH_Spur.dbo.dimDate b on a.day = b.calendarDay Inner join DWH_Spur.dbo.dimStore c on a.storeId = c.storealternateKey Where TradingstatusTypeId = 1 And Not Exists ( Select datekey, storekey From DWH_Spur.dbo.factTradingStore_11 x Where b.datekey = x.datekey And c.storekey = x.storekey )

Update FactTradingStore_11 Set DataReceived = 'Yes', DateUpdated = GetDate() Where Exists (Select Top 1 DateKey From FactSale_1111111 Where DateKey = FactTradingStore_11.DateKey And StoreKey = FactTradingStore_11.StoreKey)

Update FactTradingStore_11 Set DataReceived = 'No', DateUpdated = GetDate() Where DataReceived Is Null

3.2 UpdateFactTradingStore_36 Load trading store table (Month, Brand)

Select c.DateKey, e.StoreKey, Count(Distinct a.StoreKey) As CountDistinctStore, Count(a.StoreKey) As CountStore, @EventLogDetailId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From FactTradingStore_11 a Inner Join DimDate b on a.DateKey = b.DateKey Inner Join DimDateMonth c on b.CalendarYearMonth = c.CalendarYearMonth Inner Join DimStore d on a.StoreKey = d.StoreKey Inner Join DimStoreBrand e on d.BrandName = e.BrandName And e.IsDeleted = 0 Where a.DataReceived = 'Yes' And Not Exists (Select DateKey From FactTradingStore_36 Where DateKey = c.DateKey And StoreKey = e.StoreKey) Group By c.DateKey, e.StoreKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 12 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.3 UpdateFactSale_1110011 Load Day, Day Part, Store, Waiter, OUTM aggregate Insert Into FactSale_1110011(DateKey, TimeKey, StoreKey, WaiterKey, OUTM, TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, RedeemValue, TicketClaim, CustomerTip, TransactionType, OrderType, TableNo, Station, ItemCount, CustomerCount, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select Distinct DateKey, TimeKey, StoreKey, WaiterKey, OUTM, (IsNull(TotalCost,0)) AS TotalCost, IsNull(TotalDiscount,0) as TotalDiscount, (IsNull(BillAmount,0)) BillAmount, (IsNull(BillDiscount,0)) BillDiscount, (IsNull(BillTax,0)) BillTax, (IsNull(RedeemValue,0)) RedeemValue, (IsNull(TicketClaim,0)) TicketClaim, (IsNull(CustomerTip,0)) CustomerTip, TransactionType, OrderType, TableNo, Station, ItemCount, CustomerCount, @EventLogDetailId, 0 as isSummarised, GetDate() DateCreated, GetDate() DateUpdated From FactSale_1111111 Where isSummarised = 0

3.4 UpdateFactSale_1116111 Load Day, Day Part, Store, Waiter, OUTM aggregate

Insert Into FactSale_1116111(DateKey, TimeKey, StoreKey, ItemKey, PromotionKey, WaiterKey, OUTM, Quantity, [Value], LineDiscount, TransactionType, OrderType, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select a.DateKey, a.TimeKey, a.StoreKey, c.ItemKey, a.PromotionKey, a.WaiterKey, a.OUTM, Sum(a.Quantity), Sum(a.[Value]), Sum(a.LineDiscount), TransactionType, OrderType, @EventLogDetailId As EventDetailLogId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From FactSale_1111111 a Inner Join DimItem b on a.ItemKey = b.ItemKey Inner Join DimItemGroup c on b.[Group] = c.[Group] And c.isDeleted = 0 Where a.isSummarised = 0 Group By a.DateKey, a.TimeKey, a.StoreKey, c.ItemKey, a.PromotionKey, a.WaiterKey, a.OUTM, a.TransactionType, a.OrderType

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 13 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.5 Update FactSale_1011100 Load Day, Store, PLU, Promo aggregate

Insert Into FactSale_1011100(DateKey, a.StoreKey, ItemKey, PromotionKey,Quantity, [Value], TotalCost, SellingPrice, CostPrice, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, InvoiceCount, DistinctInvoiceCount, DistinctWaiterCount, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select DateKey, a.StoreKey, a.ItemKey, PromotionKey, Sum(IsNull(Quantity,0)) As Quantity, Sum(IsNull([Value],0)) As [Value], Sum(IsNull(TotalCost,0)) AS TotalCost, Max(SellingPrice), Max(CostPrice), Sum(TotalDiscount), Sum(IsNull(BillAmount,0)), Sum(IsNull(BillDiscount,0)), Sum(IsNull(BillTax,0)), Sum(IsNull(ItemTax,0)), Sum(IsNull(LineDiscount,0)), Sum(IsNull(RedeemValue,0)), Sum(IsNull(TicketClaim,0)), Count(OUTM) As InvoiceCount, Count(Distinct OUTM) As DistinctInvoiceCount, Count(Distinct WaiterKey) As DistinctWaiterCount, @EventLogDetailId, 0 as isSummarised, GetDate(), GetDate() From FactSale_1111111 a Inner Join DimStore b on a.StoreKey = b.StoreKey Where a.isSummarised = 0 Group By a.DateKey, a.StoreKey, a.ItemKey, a.PromotionKey

3.6 UpdateFactSale_1001100_Average Load Day, PLU, Promo averages aggregate

Insert Into FactSale_1001100_Average(DateKey, ItemKey, PromotionKey, Quantity, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, CountDistinctStore, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select a.DateKey, a.ItemKey, a.PromotionKey, (Sum(Quantity) / c.StoreCount) As Quantity, (Sum([value]) / StoreCount) As [Value], (Sum(TotalCost) / StoreCount) As TotalCost, (Sum(TotalDiscount) / StoreCount), (Sum(BillAmount) / StoreCount), (Sum(BillDiscount) / StoreCount), (Sum(BillTax) / StoreCount), (Sum(ItemTax) / StoreCount), (Sum(LineDiscount) / StoreCount), (Sum(RedeemValue) / StoreCount), (Sum(TicketClaim) / StoreCount), Count(Distinct a.StoreKey), @EventLogDetailId, 0 As isSummarised, GetDate(), GetDate() From FactSale_1011100 a Inner Join DimStore b on a.StoreKey = b.StoreKey Inner Join ( Select DateKey, Count(Distinct StoreKey) StoreCount From FactTradingStore_11 Where DataReceived = 'Yes' Group By DateKey ) c On a.DateKey = c.DateKey Where a.isSummarised = 0 Group by a.DateKey, a.ItemKey, a.PromotionKey, c.StoreCount

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 14 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.7 UpdateFactSale_1011100_Average Load Day, Store, PLU, Promo averages aggregate

Insert Into FactSale_1011100_Average(DateKey, StoreKey, ItemKey, PromotionKey,Quantity, [Value], TotalCost, SellingPrice, CostPrice, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, InvoiceCount, DistinctInvoiceCount, DistinctWaiterCount, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select a.DateKey, a.StoreKey, a.ItemKey, PromotionKey, Sum(IsNull(Quantity,0) / c.StoreCount) As Quantity, Sum(IsNull([Value],0) / c.StoreCount) As [Value], Sum(IsNull(TotalCost,0) / c.StoreCount) AS TotalCost, Max(SellingPrice), Max(CostPrice), Sum(TotalDiscount), Sum(IsNull(BillAmount,0) / c.StoreCount), Sum(IsNull(BillDiscount,0) / c.StoreCount), Sum(IsNull(BillTax,0) / c.StoreCount), Sum(IsNull(ItemTax,0) / c.StoreCount), Sum(IsNull(LineDiscount,0) / c.StoreCount), Sum(IsNull(RedeemValue,0) / c.StoreCount), Sum(IsNull(TicketClaim,0) / c.StoreCount), Count(OUTM) As InvoiceCount, Count(Distinct OUTM) As DistinctInvoiceCount, Count(Distinct WaiterKey) As DistinctWaiterCount, @EventLogDetailId, 0 as isSummarised, GetDate(), GetDate() From FactSale_1111111 a Inner Join DimStore b on a.StoreKey = b.StoreKey Inner Join ( Select DateKey, Count(Distinct StoreKey) * 1.0 As StoreCount From FactTradingStore_11 Where DataReceived = 'Yes' Group By DateKey ) c On a.DateKey = c.DateKey Where a.isSummarised = 0 Group by a.DateKey, a.StoreKey, a.ItemKey, a.PromotionKey, c.StoreCount

3.8 UpdateFactSale_1010000 Load Day, Store aggregate Insert Into FactSale_1010000(DateKey, StoreKey, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, RedeemValue, TicketClaim, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select DateKey, StoreKey, Sum(isnull([Value],0)) As [Value], Sum(isnull(TotalCost,0)) As Cost, Sum(IsNull(TotalDiscount,0)) As TotalDiscount, Sum(isnull(BillAmount,0)) As BillAmount, Sum(isnull(BillDiscount,0)) As BillDiscount, Sum(IsNull(BillTax,0)) As BillTax, Sum(IsNull(RedeemValue,0)) As RedeemValue, Sum(IsNull(TicketClaim, 0)) As TicketClaim, @EventLogDetailId, 0 as isSummarised, getdate() As DateCreated, getdate() As DateUpdated From FactSale_1110011 Where isSummarised = 0 Group By DateKey, StoreKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 15 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.9 UpdateFactSale_3001100_Average Load Month, PLU, Promo average aggregate

Insert Into FactSale_3001100_Average(DateKey, ItemKey, PromotionKey, Quantity, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select c.DateKey, a.itemKey, a.PromotionKey, Sum(IsNull(Quantity,0)) As Quantity, sum(IsNull([Value],0)) As [Value], Sum(IsNull(TotalCost,0)) As TotalCost, Sum(IsNull(TotalDiscount,0)) As TotalDiscount, Sum(IsNull(BillAmount,0)) As BillAmount, Sum(IsNull(BillDiscount,0)) As BillDiscount, Sum(IsNull(BillTax,0)) As BillTax, Sum(IsNull(ItemTax,0)) As Tax, Sum(IsNull(LineDiscount,0)) As Discount, Sum(IsNull(RedeemValue,0)) As RedeemValue, Sum(IsNull(TicketClaim,0)) As TicketClaim, @EventLogDetailId, 0 as isSummarised, getdate(), getdate() From FactSale_1001100_Average a Inner Join dimDate b On a.DateKey = b.DateKey Inner Join dimDateMonth c On b.CalendarYear = c.CalendarYear And b.CalendarMonth = c.CalendarMonth Where a.isSummarised = 0 Group By c.DateKey, a.ItemKey, a.PromotionKey

3.10 UpdateFactSale_3006100_Average Load Month, MenuName, Promo average aggregate Insert Into FactSale_3006100_Average(DateKey, ItemKey, PromotionKey, Quantity, [Value], TotalCost, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select a.DateKey, c.ItemKey, a. PromotionKey, Sum(Quantity), Sum([Value]), Sum(TotalCost), Sum(BillAmount), Sum(BillDiscount), Sum(BillTax), Sum(ItemTax), Sum(LineDiscount), Sum(RedeemValue), Sum(TicketClaim), @EventLogDetailId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From Factsale_3001100_Average a Inner Join DimItem b on a.ItemKey = b.ItemKey Inner Join DimItemMenuName c on b.MenuName = c.MenuName

And b.CurrentMenu = c.CurrentMenu And b.ItemType = c.ItemType And b.[Group] = c.[Group] And b.SubGroup = c.SubGroup And b.Class = c.Class And b.SubClass = c.SubClass And b.TargetGroup = c.TargetGroup Group By a.DateKey, c.ItemKey, a.PromotionKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 16 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.11 UpdateFactSale_3011100 Load Month, Store, PLU, Promo aggregate

Insert Into FactSale_3011100(DateKey, StoreKey, ItemKey, PromotionKey, Quantity, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select c.DateKey, a.StoreKey, a.ItemKey, PromotionKey, Sum(IsNull(Quantity,0)) As Quantity, sum(IsNull([Value],0)) As [Value], Sum(IsNull(TotalCost,0)) As Cost, Sum(IsNull(TotalDiscount,0)) As TotalDiscount, Sum(IsNull(BillAmount,0)) As BillAmount, Sum(IsNull(BillDiscount,0)) As BillDiscount, Sum(IsNull(BillTax,0)) As BillTax, Sum(IsNull(ItemTax,0)) As Tax, Sum(IsNull(LineDiscount,0)) As Discount, Sum(IsNull(RedeemValue,0)) As RedeemValue, Sum(IsNull(TicketClaim,0)) As TicketClaim, @EventLogDetailId, 0 as isSummarised, getdate(), getdate() From FactSale_1011100 a Inner Join dimDate b On a.DateKey = b.DateKey Inner Join dimDateMonth c On b.CalendarYear = c.CalendarYear And b.CalendarMonth = c.CalendarMonth Where a.IsSummarised = 0 Group By c.DateKey, a.StoreKey, a.itemKey, a.PromotionKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 17 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.12 UpdateFactSale_3010000 Load Month, Store aggregate Insert Into FactSale_3010000(DateKey, StoreKey, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, RedeemValue, TicketClaim, EventDetailLogid, isSummarised, DateCreated, DateUpdated) Select c.DateKey, a.StoreKey, Sum([Value]), Sum(TotalCost), Sum(TotalDiscount), Sum(BillAmount), Sum(BillDiscount), Sum(BillTax), Sum(RedeemValue), Sum(TicketClaim), @EventLogDetailId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From Factsale_1010000 a Inner Join DimDate b on b.DateKey = a.DateKey Inner Join DimDateMonth c on c.CalendarYearMonth = b.CalendarYearMonth Where a.isSummarised = 0 Group By c.DateKey, a.StoreKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 18 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.13 UpdateFactStoreOperation_31 Load FactStoreOperation (Month, Store)

Insert Into FactStoreOperation_31(DateKey, StoreKey, FranchiseFee, AdvertisingFee, DeclaredTurnover, OpsTurnover, AreaManager, TradingStatus, DateCreated, DateUpdated) Select c.DateKey, a.StoreKey, b.dec_roy_paid As FranchiseFee, b.dec_adv_paid As AdvertisingFee, b.Dec_To_Total, f.OperationsTurnover, IsNull(g.FirstName + ' ' + g.Surname, '-Not Assigned-') As AreaManager, e.TradingStatusType, Getdate(), Getdate() From DimStore a Inner Join Nilo.Smart.Dbo.Roy_Declarations b on a.StoreAlternateKey = b.Dec_Store Inner Join DimDateMonth c On b.Dec_Year = c.CalendarYear And b.Dec_Month = c.CalendarMonth Inner Join Nilo.Smart.dbo.TradingStatus d On a.StoreAlternateKey = d.StoreId And b.Dec_Year = d.[Year] And b.Dec_Month = d.[Month] Inner Join Nilo.Smart.dbo.TradingStatusType e on d.TradingStatusTypeId = e.TradingStatusTypeId Left Outer Join Nilo.Smart.Dbo.OperationsInformation f on a.StoreAlternateKey = f.StoreId And b.Dec_Year = f.[Year] And b.Dec_Month = f.[Month] Left Outer Join Nilo.Smart.dbo.Employee g on f.EmployeeId = g.EmployeeId Where Not Exists ( Select DateKey From FactStoreOperation_31 Where DateKey = c.DateKey And StoreKey = a.StoreKey And FranchiseFee = b.dec_roy_paid And AdvertisingFee = b.dec_adv_paid And TradingStatusType = e.TradingStatusType )

3.14 UpdateFactSale_4001100_Average Load Quarter, PLU averages aggregate

Insert Into FactSale_4001100_Average(DateKey, ItemKey,PromotionKey,Quantity, [Value],TotalCost,TotalDiscount,BillAmount,BillDiscount,BillTax,ItemTax,Line Discount,RedeemValue,TicketClaim,EventDetailLogId,isSummarised,DateCreated,D ateUpdated) Select c.DateKey, a.ItemKey, a.PromotionKey, Sum(a.Quantity), Sum(a.[Value]), Sum(a.TotalCost), Sum(a.TotalDiscount), Sum(BillAmount), Sum(a.BillDiscount), Sum(a.BillTax), Sum(a.ItemTax), Sum(a.LineDiscount), Sum(a.RedeemValue), Sum(TicketClaim), @EventLogDetailId As EventDetailLogId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From FactSale_3001100_Average a Inner Join DimDateMonth b on a.DateKey = b.DateKey Inner Join DimDateQuarter c on b.CalendarYear = c.CalendarYear And b.CalendarMonth = c.CalendarMonth Where a.isSummarised = 0 Group By c.DateKey, a.ItemKey, a.PromotionKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 19 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3.15 UpdateFactSale_4006100_Average Load Quarter, MenuName averages aggregate

Insert Into FactSale_4006100_Average(DateKey,ItemKey,PromotionKey,Quantity, [Value],TotalCost,TotalDiscount,BillAmount,BillDiscount,BillTax,ItemTax,Line Discount,RedeemValue,TicketClaim,EventDetailLogId,isSummarised,DateCreated,D ateUpdated) Select c.DateKey, e.ItemKey, a.PromotionKey, Sum(Quantity), Sum([Value]),Sum(TotalCost),Sum(TotalDiscount),Sum(BillAmount),Sum(BillDisco unt),Sum(BillTax),Sum(ItemTax),Sum(LineDiscount),Sum(RedeemValue),Sum(Ticket Claim),0, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From Factsale_3006100_Average a Inner Join DimDateMonth b on a.DateKey = b.DateKey Inner Join DimDateQuarter c on b.CalendarYear = c.CalendarYear And b.CalendarMonth = c.CalendarMonth Inner Join DimItem d on a.ItemKey = d.ItemKey Inner Join DimItemMenuName e on d.Menuname = e.MenuName And d.CurrentMenu = e.CurrentMenu And d.ItemType = e.ItemType And d.[Group] = e.[Group] And d.SubGroup = e.SubGroup And d.Class = e.Class And d.SubClass = e.SubClass And d.TargetGroup = e.TargetGroup Where a.isSummarised = 0 Group By c.DateKey, e.ItemKey, a.PromotionKey

3.16 UpdateFactSale_2001100_Average Load ReportingWeek, PLU, Promo average aggregate

Insert Into FactSale_2001100_Average(DateKey, ItemKey, PromotionKey, Quantity, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select c.DateKey, a.itemKey, a.PromotionKey, Sum(IsNull(Quantity,0)) As Quantity, sum(IsNull([Value],0)) As [Value], Sum(IsNull(TotalCost,0)) As TotalCost, Sum(IsNull(TotalDiscount,0)) As TotalDiscount, Sum(IsNull(BillAmount,0)) As BillAmount, Sum(IsNull(BillDiscount,0)) As BillDiscount, Sum(IsNull(BillTax,0)) As BillTax, Sum(IsNull(ItemTax,0)) As Tax, Sum(IsNull(LineDiscount,0)) As Discount, Sum(IsNull(RedeemValue,0)) As RedeemValue, Sum(IsNull(TicketClaim,0)) As TicketClaim, 0, 0 as isSummarised, GetDate(), GetDate() From FactSale_1001100_Average a Inner Join dimDate b On a.DateKey = b.DateKey Inner Join DimDateReportingWeek c On b.ReportingYear = c.ReportingYear And b.ReportingWeek = c.ReportingWeek Where a.isSummarised = 0

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 20 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

Group By c.DateKey, a.ItemKey, a.PromotionKey

3.17 UpdateFactSale_2006100_Average Load ReportingWeek, MenuName, Promo average aggregate

Insert Into FactSale_2006100_Average(DateKey, ItemKey, PromotionKey, Quantity, [Value], TotalCost, TotalDiscount, BillAmount, BillDiscount, BillTax, ItemTax, LineDiscount, RedeemValue, TicketClaim, EventDetailLogId, isSummarised, DateCreated, DateUpdated) Select a.DateKey, c.ItemKey, a. PromotionKey, Sum(Quantity), Sum([Value]), Sum(TotalCost), Sum(TotalDiscount), Sum(BillAmount), Sum(BillDiscount), Sum(BillTax), Sum(ItemTax), Sum(LineDiscount), Sum(RedeemValue), Sum(TicketClaim), @EventLogDetailId, 0 As isSummarised, GetDate() As DateCreated, GetDate() As DateUpdated From Factsale_2001100_Average a Inner Join DimItem b on a.ItemKey = b.ItemKey Inner Join DimItemMenuName c on b.MenuName = c.MenuName And b.CurrentMenu = c.CurrentMenu And b.ItemType = c.ItemType And b.[Group] = c.[Group] And b.SubGroup = c.SubGroup And b.Class = c.Class And b.SubClass = c.SubClass And b.TargetGroup = c.TargetGroup Group By a.DateKey, c.ItemKey, a.PromotionKey

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 21 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

Update isSummarised This is the same as described above.

4 Update Control Tables The purpose of this process is to monitor the quality of our data. The design attempts to answer the follwong questions:

1. How many IM, ID have we received for the month 2. How many valid / invalid records 3. Compare IM (daily invoice totals) to declared turnover

Add the following step to the framework:

StepID StepName Command IsActive 1 Update IM Control Exec Live.UpdateIM_Control 1 2 Update ID Control Exec Live.UpdateID_Control 1

How to run this step?:

4. SubmitJobs ‘Update Control Tables’ 5. ExecuteJobs ‘Update Control Tables’

Dependencies 1. DimDate, DimDateMonth, DimStore, FactStoreOperation_31

Known Issues & Limitations: 1. None

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 22 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

A. Appendix – Facts & Aggregate Table(s)

1. FactSale_1111111 The table stores the lowest sales facts. ONLY sales items, where itemtype equals item, are loaded into this fact.

FactSale_ 1 1 1 1 1 1 1 Day TimeDayPart Store Item(PLU) Promotion Waiter OUTM

Column Data Type Length Comments DateKey int NULL TimeKey int NULL StoreKey int NULL ItemKey int NULL PromotionKey int NULL WaiterKey int NULL OUTM varchar 20 Quantity float NULL Value decimal NULL VAT Inclusive SellingPrice decimal NULL CostPrice decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL CustomerTip decimal NULL TransactionType varchar 3 OrderType varchar 3 TableNo varchar 7 Station varchar 3 Split int NULL ItemCount decimal NULL CustomerCount decimal NULL FileName varchar 50 EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 23 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

2. FactSaleModifier_1111111 The table stores the lowest sales modifiers. ONLY modifiers, where itemtype is option OR modifier, are loaded into this fact.

FactSaleModifier_ 1 1 1 1 1 1 1 Day TimeDayPart Store Item(PLU) Promotion Waiter OUTM

Column Data Type Length Comments DateKey int NULL TimeKey int NULL StoreKey int NULL ItemKey int NULL PromotionKey int NULL WaiterKey int NULL OUTM varchar 20 Quantity float NULL Value decimal NULL VAT Inclusive SellingPrice decimal NULL CostPrice decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL CustomerTip decimal NULL TransactionType varchar 3 OrderType varchar 3 TableNo varchar 7 Station varchar 3 Split int NULL ItemCount decimal NULL CustomerCount decimal NULL FileName varchar 50 EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 24 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

3. FactSaleSetMenu_1111111 The table stores the lowest sales modifiers. ONLY set menu items, where itemtype is menu_item, are loaded into this fact.

FactSaleSetMenu_ 1 1 1 1 1 1 1 Day TimeDayPart Store Item(PLU) Promotion Waiter OUTM

Column Data Type Length Comments DateKey int NULL TimeKey int NULL StoreKey int NULL ItemKey int NULL PromotionKey int NULL WaiterKey int NULL OUTM varchar 20 Quantity float NULL Value decimal NULL VAT Inclusive SellingPrice decimal NULL CostPrice decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL CustomerTip decimal NULL TransactionType varchar 3 OrderType varchar 3 TableNo varchar 7 Station varchar 3 Split int NULL ItemCount decimal NULL CustomerCount decimal NULL FileName varchar 50 EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 25 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

4. FactPurchase_1111 The table stores the lowest purchase facts.

FactPurchase_ 1 1 1 1 Day Store Product Supplier

Column Data Type Length Comments DateKey int NULL StoreKey int NULL ProductKey int NULL SupplierKey int NULL Link varchar 50 PaymentDate datetime NULL ShipmentDate datetime NULL Cost decimal NULL Quantity decimal NULL Price decimal NULL Vat decimal NULL UnitOfMeasure varchar 10 StoreReference varchar 20 PaymentReference varchar 20 ExcludesFranchiseFee varchar 5 FileName varchar 50 EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

5. FactTradingStore_11 StoreTradingDay maintained in the SMART system is used to populate this fact. A record for a store will ONLY exists in this table if the store traded that day. Table SmartStores and lowest level facts are used to update columns, LockDown and DataReceived.

TradingStore_ 1 1 Day Store

Column Data Type Length Comments DateKey int NULL StoreKey int NULL LockedDown varchar 20 DataReceived varchar 20 Valid varchar 20 This colum is not used at the moment DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 26 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

6. FactTradingStore_36 This table summarises data in table FactTradingStore_11.

TradingStore_ 3 6 Month Brand

Column Data Type Length Comments DateKey int NULL StoreKey int NULL CountDistinctStore int NULL CountStore int NULL How many store datadays? EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

7. FactSale_1110011 This is an aggregate of table FactSale_1111111 and is equivalent to daily invoice totals.

FactSale_ 1 1 1 0 0 1 1 Day TimeDayPart Store Waiter OUTM

Column Data Type Length Comments DateKey int NULL TimeKey int NULL StoreKey int NULL WaiterKey int NULL OUTM varchar 20 Value decimal NULL VAT Inclusive TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL CustomerTip decimal NULL TransactionType varchar 3 OrderType varchar 3 TableNo varchar 7 Station varchar 3 ItemCount decimal NULL CustomerCount decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 27 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

8. FactSale_1116111 This is an aggregate of table FactSale_1111111 and is equivalent to daily invoice totals.

FactSale_ 1 1 1 6 1 1 1 Day TimeDayPart Store MenuName Promotion Waiter OUTM

Column Data Type Length Comments DateKey int NULL TimeKey int NULL StoreKey int NULL ItemKey int NULL PromotionKey int NULL WaiterKey int NULL OUTM varchar 20 Quantity float NULL Value decimal NULL VAT Inclusive LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL CustomerTip decimal NULL TransactionType varchar 3 OrderType varchar 3 ItemCount decimal NULL CustomerCount decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 28 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

9. FactSale_1011100 This is an aggregate of table FactSale_1111111 and is equivalent to daily plu sales OR runtot.

FactSale_ 1 0 1 1 1 0 0 Day Store Item (PLU) Promotion

Column Data Type Length Comments DateKey int NULL StoreKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL SellingPrice decimal NULL CostPrice decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL InvoiceCount int NULL DistinctInvoiceCount int NULL DistinctWaiterCount int NULL isSummarised bit NULL EventDetailLogId int NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 29 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

10. FactSale_1001100 This is an aggregate of table FactSale_1011100 and is daily PLU average.

FactSale_ 1 0 0 1 1 0 0 Day Item (PLU) Promotion

Column Data Type Length Comments DateKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL CountDistinctStore int NULL CountLineDiscount int NULL CountDistinctTicketClaim int NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 30 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

11. FactSale_1010000 This is an aggregate of table FactSale_1110011and is daily sales totals (daily turnover).

FactSale_ 1 0 1 0 0 0 0 Day Store

Column Data Type Length Comments DateKey int NULL StoreKey int NULL Value decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

12. FactSale_3001100 This is an aggregate of table FactSale_1001100 and is monthly PLU average.

FactSale_ 3 0 0 1 1 0 0 Month Item (PLU) Promotion

Column Data Type Length Comments DateKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 31 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

13. FactSale_3011100 This is an aggregate of table FactSale_1011100 and is equivalent to monthy plu sales OR runtot_summary.

FactSale_ 3 0 1 1 1 0 0 Month Store Item (PLU) Promotion

Column Data Type Length Comments DateKey int NULL StoreKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL isSummarised bit NULL EventDetailLogId int NULL DateCreated datetime NULL DateUpdated datetime NULL

14. FactSale_3010000 This is an aggregate of table FactSale_1010000 and is equivalent to the monthly sales totals (monthly turnover).

FactSale_ 1 0 1 0 0 0 0 Month Store

Column Data Type Length Comments DateKey int NULL StoreKey int NULL Value decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 32 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

DateUpdated datetime NULL

15. FactSale_3006100 This is an aggregate of table FactSale_3001100 and is monthly menuname average.

FactSale_ 3 0 0 6 1 0 0 Month MenuName Promotion

Column Data Type Length Comments DateKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 33 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

16. FactSale_4001100 This is an aggregate of table FactSale_3001100 and is quarterly PLU average.

FactSale_ 4 0 0 1 1 0 0 Quarter Item (PLU) Promotion

Column Data Type Length Comments DateKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 34 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

17. FactSale_4006100 This is an aggregate of table FactSale_3006100 and is quaterly menuname average.

FactSale_ 4 0 0 6 1 0 0 Quarter MenuName Promotion

Column Data Type Length Comments DateKey int NULL ItemKey int NULL PromotionKey int NULL Quantity float NULL Value decimal NULL ItemTax decimal NULL LineDiscount decimal NULL TotalCost decimal NULL TotalDiscount decimal NULL BillAmount decimal NULL BillDiscount decimal NULL BillTax decimal NULL RedeemValue decimal NULL TicketClaim decimal NULL EventDetailLogId int NULL isSummarised bit NULL DateCreated datetime NULL DateUpdated datetime NULL

18. FactStoreOperation_31

Column Data Type Length Comments DateKey int NULL StoreKey int NULL FranchiseFee money NULL AdvertisingFee money NULL AreaManager varchar 50 DeclaredTurnover money NULL OpsTurnover money NULL TradingStatus varchar 40 DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 35 of 36 SPUR GROUP PTY DATA WAREHOUSE – LOAD FACTS & AGGREGATE

19. ID_[Site]_Control

Column Data Type Length Site varchar 2 Year int NULL Month int NULL RecordCount int NULL ValidRecordCount int NULL InvalidRecordCount int NULL ValueInclDiscount decimal NULL ValueExclDiscount decimal NULL ValidValueExclDiscount decimal NULL InvalidValueExclDiscount decimal NULL ValueInclDiscntExclVAT numeric NULL DeclaredTurnover money NULL DateCreated datetime NULL DateUpdated datetime NULL

20. ID_[Site]_Control

Column Data Type Length Site varchar 2 Year int NULL Month int NULL IMCount int NULL RecordCount int NULL ValidRecordCount int NULL InvalidRecordCount int NULL ValueExclDiscount decimal NULL ValidValueExclDiscount decimal NULL InvalidValueExclDiscount decimal NULL DateCreated datetime NULL DateUpdated datetime NULL

Fact & Aggregate Process Version 1.3 June 23, 2010 Page 36 of 36