You are on page 1of 5

if object_id('tempdb..

#BlankAreas',N'U') is not null


drop table #BlankAreas
/****** Script for SelectTopNRows command from SSMS ******/
SELECT DISTINCT
[TPID]
,[Area]
into #BlankAreas
FROM [PhilanthropyDataFeeds].[vw_AzureDonations]
LEFT JOIN [PhilanthropyDataFeeds].[vw_StaticGeography] ON
[CountryCode]=[tenantcountrycode]

SELECT a.[TPID]
,[FiscalYearQuarter]
,[Date] as [Fiscal Month]
,o.[OrgName] as [Account Name]
,[FiscalYear]
,[TotalEffectiveBilling] as [Azure Consumed Revenue]
,[RegistrationStatus]
,case when g.[Area] is null then b.Country else g.Country end as Country
FROM [PhilanthropyDataFeeds].[vw_AzureRevenue] a
LEFT JOIN [PhilanthropyDataFeeds].[vw_CalendarDate] ON [billingmonthDImDateKey]=[Date]
Left JOIN [PhilanthropyDataFeeds].[vw_AzureRegistrations] d ON a.[RegistrationID]=d.
[Registrationid]
LEFT JOIN [PhilanthropyDataFeeds].[vw_nonprofit] o ON d.[Registrationnumber]=o.
[RegistrationNumber]
LEFT JOIN [PhilanthropyDataFeeds].[vw_StaticGeography] g ON
[CountryCustom]=o.OrgCountry
LEFT JOIN #BlankAreas b ON a.TPID=b.TPID

WHERE [Date] IN ('2019-07-01','2019-08-01','2019-09-01','2019-10-01','2019-11-


01','2019-12-01','2020-01-01','2020-02-01','2020-03-01','2020-04-01','2020-05-01','2020-
06-01') AND

[RegistrationStatus] <> 'Fraud'


AND a.TPID NOT IN
(13133062,1131414,13451690,10393293,3127982,40207702,11787269,6119170,7811968,1437950,952
611,1627206,698778,3242970,603992,1736693,952660,4062779,3695048,936192,11193535,704832,4
7981063,2431895,521378,13170622,2858337,1811277,882056,2053237,17239665,2864189,657903,30
100701,1426770,9198491,619322,1388695,20437023,2313857,757344,1019087,692202,2819085,2225
6258,2160780,2623050,29100842,891088,4111188,13106795,6140443,22023697,987879,9586135,157
53322,8232005,1327159,1566066,15100468,5756083,16440750,898136,2657945,37442895,32052880,
1884880,10500321,2297720,955645,13666199,26283845,980754,604293,2053221,695564,12608282,7
954555,14400703,2510645,8387333,961981,33577926,2581250,2307536,5065605,1836491,9300640,7
648424,798517,2356910,8388817,6130146,1782625,962159,604438,11195994,5964133,11396812,591
2591,7635548,13512068,976114,1025420,5026443,640709,22771734,642098,11058277,8056599,8861
646,4474198,619217,1371132,1552716,2131756,5011202,1874883,9502276,2668081,21199975,60416
2,2541836,2834947,1545339,10066608,4808564,14375113,31090224,25250611,5101469,6302029,642
623,26075872,977598,641935,14945949,14787699,1180718,1107863,3710071,1725620,9891908,9426
94,969400,1391648,4479479,644283,10238270,21786027,12372096,8264229,3217737,5107475,93898
32,1789441,1104755,7623829,7097806,594926,645891,17156304,25127250,10492804,29130569,2942
1488,40114191,20446964,39076751,23354731,40880218,40902086,5170870,20069425,22023971,1325
2851,18324909,39482828,35164874,41525002,20606860,23525522,39775601,39775633,4891604,3564
9116,34066246,42255908,2787461,5471967,14043435,31010228,15360891,7137938,28777774,387477
69,23160303,30716871,31865735,9961120,9961138,6892168,35929257,11360059,39171554,4791943,
33615812,18824422,5319129,6167600,1485118,23612015,35371395,5916965,1251704,2163016,64701
0,3195018,34905915,9693857,1511635,9647550,3984869,1899856,15741346,3013081,39669518,1039
5663,1258008,34956371,2713794,1260984,36366342,19356001,39310278,41450025,18250343,152584
15,27279066,22877309,10221840,25747102,18440557,4218858,15090337,982741,21712201,39106117
,8796643,38784308,16123707,40359160,21712193,21759724,41532083,13520651,4907564,5405104,3
8310190,38596898,39154788,2531826,1100392,50178680,9676795,2093465,3584058,60251003,77892
46,8534356,30565405,20115435,38332490,1119287,38887986,43390218,16787739,9276240,1274902,
18087750,31534440,9308182,14677251,6944691,13885870,3720468,2295247,32052889,38694489,129
54734,40847970,632120,42313370,12015413,2251710,40621279,37614238,22166048,2644666,581146
9,13099895,32915703,33243118,32915698,32915712,33243121,32915676,32915705,32915710,329156
94,32915689,32915682,32915686,32915713,32915684,33243115,32915704,33243112,32915680,32915
690,32915685,32915695,32915699,32915706,33243119,33243111,32915688,32915681,33243110,3324
3120,32915687,32915692,32915691,32915679,32915693,32915696,32915677,32915708,32915678,332
43122,32915714,32915702,32915707,32915697,33243113,33243116,33243109,33243114,32915683,33
243117,32915701,32915709,32915711,36656690,25691014,22350869,19449048,30221856,18500878,1
8500879,39919787,10997579,17767022,30484242,19124731,39773237,17242332,5353356,3441491,39
269829,11213626,2620701,20082541,9265902,23144762,2340330,13609586,763744,4908483,1106282
1,15200938,3212769,35674596,9658461,12672657,20883370,38055923,38481892,38906169,20651880
,30183088,8632204,19555975,30174727,20744260,2382357,4021605,15813322,15566904,35252165,4
044507,16170117,4321629,2491346,17169542,1321252,28903537,1817045,7855276,3878102,1520336
6,18702471,22368834,26014128,38018069,39710266,40109891,42476227,24233506,15203365,180513
72,46348700,14250157,43924035,1953595,12815484,30318216,5934174,40288045,29999740,7613487
,1290708,1136775,22212726,22677169,30685506,31554045,23143635,22254876,20953122,9328859,3
460621,4492942,14596148,16504646,21889791,32217482,33437432,35109906,39269115,42604357,42
96106,5165087,15796001,45196638,44009412,1846368,1965625,5638895,1546489,4546105,655422,3
8975017,30597645,1177445,726168,31513270,19242043,37355717,6821029,31497901,5901897,18690
962,33500690,7872861,14046274,1412771,22383763,32547349,19326627,24648975,4290945,2099305
4,1800084,6761375,61125769,61125765,61125767,61125761,61125766,61125763,61125764,61125762
,61125760,22321398,38841245,17534187,22873176,37487557,38693651,5908619,32333144,628331,2
2962114,12834042,16257828,680595,5403442,2233883,39405899,1037029,1102459,25227010,111078
66,14731176,38838286,672926,16139936,1171582,15894975,1035837,4928110,33986053,1835581,22
212957,13503348,19452062,41238069,3401561,20000255,40124988,17814996,23638667,13848233,88
29640,2389880,18759366,20948444,20950780,35429676,29576112,20002449,18545725,31231220,324
15792,36402810,37978790,45265517,45265688,31187429,17327699,41791979,6192131,13506997,315
74076,1072032,14165392,38945501,39105963,11239617,18504778,1224143,1826115,13863210,26315
20,20194413,13853150,38359667,10651873,18470938,19288643,18469398,14641779,15156035,21900
738,36719289,17720565,31077210,18761479,23848638,11358766,20848693,14418661,33091262,3121
6113,4843370,13821264,18439247,37518081,23950149,17579540,32046308,41046091,37647966,1198
0480,39960776,17248418,29678985,20219933,34358474,21357197,21165824,30715274,31070247,217
45410,38753865,37511992,29261015,20964511,39572474,32331559,17681364,18717035,16360780,18
118634,24399490,36656723,35265637,30597778,40167306,30580092,38179183,29637406,32947209,3
4018350,25148772,15561763,25660261,14366520,21455991,9426568,14778324,22079258,20437036,2
2477707,15179552,17148887,28941847,21984420,39765951,21576347,18652711,19049825,37702927,
30403682,37452614,1372741,21345012,21345013,38431205,42503173,42503962,36737848,44717011,
29908711,39090131,37601351,9037673,42048734,40216087,6088864,32479924,11834036,12059363,7
667362,13952966,40989916,16044178,15334526,6997211,8695705,38205181,19887596,38108952,110
3026,35685106,24987251,5452555,7173078,1879678,32588602,14788386,12284985,31074513,376160
48,32397740,5712570,2697117,31306650,25249075,5237636,29235187,9155782,6288824,17003164,9
134244,15314167,23798135,212721,19414333,19912386,12605636,16727345,24553924,14311350,116
88134,12083291,32032997,6417371,37789564,37314640,30395765,43186491,17145208,17775649,524
6084,42268319,46231060,41700992,32374097,2518949,1029273,39134041,23891477,11546191,37975
805,42398795,23609782,16635434,14434682,18047620,38768279,12770215,38971175,7102180,16709
342,20735340,2205118,4303059,4890076,6387735,16411169,32619936,50236810,14932374,38886960
,46700621,2525432,2165622,3885375,8990787,19295130,39244665,1030165,34158836,34531055,206
9860,12657047,9637899,30035030,31948653,13133017,1300965,718688,654751,16098375,13760662,
45310094,40100403,1287374,43768949,4193338,40104248,2693049,24006858,26268672,39630034,22
314984,1026082,2648427,39388536,17310098,6770428,38384035,29226861,37252986,15834412,2681
473,43343801,18631411,36467179,38176440,28638918,4124124,30212020,22380838,32081288,37845
31,23769580,24111764,7052331,4632004,967285,34698478,34781921,35910184,6051922,15836259,2
0926776,43794548,16183737,16183738,34884408,17348607,39765331,14717905,10678173,5818516,7
504915,11756527,12583603,40151500,25983427,4990462,16339851,35939627,38333771,23413006,39
331608,21006007,20438135,13544859,670481,7694885,2838769,1302076,2311625,967516,6055668,1
7402839,968857,15095489,40217232,18915557,1346262,29505987,47999621,4406577,18446762,5429
3657,7995371,36268089,13907527,9087999,3520564,33741791,634872,1403116,17721803,19137085,
41971102,8213736,8266334,2366368,32126133,3142539,13513684,11803982,1319879,3145740,38373
804,27217265,16654775,4734872,16017678,12616288,22841665,4534065,15768608,33986319,313235
21,14263235,31672999,25057614,16297987,36788508,36832881,36832340,18761530,37675613,12252
397,5088414,2076710,24550640,4063983,9441577,14183405,36217866,33991639,32407150,38552430
,17418659,35590322,37707637,35252751,36384889,13545691,10058170,17780232,30527983,1418340
6,17394994,28908268,22487348,15816995,1514191,32130912,2532756,39479804,11398418,22117647
,38664092,24818470,26304730,40368191,1447916,21924033,15952571,2837847,6803499,5316701,64
32081,17977928,41354785,6311895,21835208,29964780,33546048,5815380,35131126,16297262,3527
8322,36743664,30752707,9865603,34544554,36269251,36278299,33402484,41940740,39876950,1514
294,30589321,17211735,18595738,22239020,31575251,41383033,14809648,14892319,657888,898922
4,7275778,3293273,13541009,13277052,35854492,18603119,7046177,3138610,36747574,33549500,5
947625,20014020,38442858,16682057,40247170,30192281,37031712,38950571,36154802,22608008,1
7569259,7203054,13402831,21088233,13931575,13076251,1470415,33681997,34050330,34478012,36
754380,42985628,9689439,1025750,26200094,38403735,12649444,30454825,38786007,4955935,1116
340,17814849,2756370,1823329,10777887,11046977,1439537,925824,18115121,8816627,12649551,1
171952,1368445,11901152,18183635,35061139,37567497,15895570,17877489,37883522,13535219,70
88069,25637292,12068843,36728792,8967827,11783226,42013644,32472476,42668829,20468063,331
04653,20277320,19374843,20846871,29325095,26227795,40790284,40790285,31061495,31070314,37
321026,39111354,38524554,38524553,14360364,24072284,24008243,16280347,15733223,38378638,3
960557,3444943,13491011,4807654,1557136,3069130,38460485,1115857,2278330,44785040,2895449
,16067826,10023847,4253387,6032331,16181931,5084725,20770119,17209539,38250346,3689284,25
643140,13881603,14851227,35374800,13963508,25165409,14885594,6526082,14885654,41918237,25
043306,2180572,2758258,6379570,2768143,39244704,3309363,4695693,14848267,15602820,6150967
,37077942,31348563,37048318,22885662,26213275,14727173,25809169,18349704,17900651,3314658
0,38376828,7144382,4905570,16060155,3415519,19304804,35120347,46635878,17597868,4567830,1
3664645,19025841,5807437,6145992,3327321,7054693,31049451,31200189,35237960,36447128,3888
3126,45021524,45020942,35945969,36502921,39092131,23253022,1476285,19887873,38635828,2400
632,6998214,32130527,16515624,11273851,33714972,3517700,4789433,14771760,14727710,1284995
3,12022510,2137179,16315589,5547051,37435797,24368934,5642119,8866172,41353428,9980572,15
643937,5423986,17591597,12963674,31622022,31736460,35741390,38230643,3270516,54445200,389
68078,52738875,55128238,58889411,56596649,62137812,55972248,975434,5291403,14251492,19823
60,51586061,32579375,31949863,2741682,24554101,1473582,2046220,38336716,30597734,668919,2
454336,2508506,644328,1811844,922661,5506749,13887691,2890885,693694,17003556,965857,3383
031,935325,6019793,4707998,683674,4006518,718432,2276778,747582,865485,5742611,2320564,27
98323,6193951,1781718,913800,4212601,706801,4331822,8260852,977539,10241013,2053252,85237
38,3249342,2957924,10715688,5734419,13664407,1450162,19726081,1303258,18890032,14520560,2
1115586,2826287,3990182,2101123,3635444,13310034,1207291,4847653,3738726,10494551,1620190
5,717423,18339910,7079164,4908219,4479474,19778506,3606276,40910229,41894442,10280394,253
81586,23958806,37057606,40173761,15247856,9202600,37195059,37195023,643515,5849166,306711
95,8418381,8418397,9673314,10380579,11781343,13500809,24965100,35463757,38782471,5578603,
29895317,32917102,5562865,38825162,39001820,17726029,17726030,32335751,29171902,32196511,
17057557,24545601,1827303,24366663,39313040,2899937,38344827,38744784,18933430,1834777,32
484645,36478464,9110484,45185954,40822087,13554599,38686809,13252896,16818597,43536256,32
375363,3861665,2454404,9004580,969401,725032,14753334,38397853,34036812,19576925,31081309
,14618368,34131176,29017502,12604915,4304164,30907925,38678449,43779060,13715185,40001028
,29149399,31433943,30162171,15091658,9833081,3625215,32400937,4386510,715494,41049510,253
31808,19988798,34540605,39449945,44517939,5947699,24723817,2200381,627193,1092408,2062685
,30281984,8253442,4919752,26158812,797759,4474750,32687636,4441492,31398151,834745,369772
08,10000353,16877959,10825373,1485094,2583613,11355593,14718872,8321701,2706265,48003377,
682126,7876218,1171345,935579,2343380,9491935,1311694,16294050,2597362,1382296,18932897,1
863617,6169158,1271656,648956,1732088,17604832,23433711,646845,752390,13973095,2476144,16
238816,13504581,17292845,5273930,724045,1569560,1698906,6031945,2489496,15713762,11287923
,2292370,1732165,2340276,5064161,635717,20286740,11000799,2062730,30127956,15223969,21618
758,25421543,5276344,19839633,13456725,1070759,36977270,1602851,2289152,2053244,1627886,4
595579,5731464,2809457,12258484,14067139,1437053,35389927,34090882,8848142,13239781,66600
5,1423400,766910,7965817,2856689,37497646,7712706,988352,18756841,2631819,1335154,2203569
9,6861429,16436337,1060943,676503,12656112,14493459,7411832,971468,1420104,4194304,883274
1,2120422,25214290,9488109,24081371,12449615,1018646,7453270,3406087,50414619,4891592,238
7067,21507277,2705067,3938566,5239860,1430554,39040097,37187386,2438783,1833259,1276039,3
6730431,22612132,5194671,1457757,1389348,36024220,17586627,3213820,1837880,8674263,644812
3,8728035,12035573,2520312,960078,1325377,32336527,1053866,2163286,1496462,19768113,68593
65,1725762,642883,25965359,1313058,11607866,2789978,18686634,6130209,13070582,1070106,721
4100,11282019,23640946,4488201,10233383,4620388,7448570,43441821,19631992,3710996,1496767
,9382152,22052516,641816,9074128,9138034,12677940,4110059,18853965,927174,2570391,1604037
6,1760483,1075945,9157092,5987133,2338928,7576023,36128937,8880295,4531339,36068624,98798
9,1572254,920585,2934371,2705825,11781239,7694389,29516242,1401455,4448413,1497062,144715
4,32907775,665535,1486382,10830771,37629438,1171622,668894,624711,22347001,14030465,37616
376,696197,23245784,12846194,30480891,1340193,2039321,9105587,638574,5284328,13017851,206
5378,37443295,37613506,13645699,780795,5242559,2926402,676523,4713912,11694793,954914,188
9182,29855407,1091937,2775476,1286470,1458257,10678301,26234293,20060554,6156626,2444278,
1200763,3469947,3329167,1256475,41483404,12060026,1210291,938685,23177266,695630,645093,3
211786,19985575,33499874,4414079,4220415,1711180,838411,3654407,13798673,13040137,1837866
6,10302593,5743022,1492428,22590641,11582570,21510712,15356176,185728,647261,2688278,3604
0121,1850349,37711196,10709359,12432121,1497619,30866622,2805006,5341070,1901499,14848327
,14822012,1544487,3241866,14289411,1901773,6163106,5355932,10258116,4234572,19223689,1465
6610,5482509,2735337,38532250,1268913,3420277,41676120,23635546,11755084,974616,740067,39
44293,25474433,4623701,695420,939482,1392789,4688565,3646135,4099574,4719737,11723140,184
73800,1363510,8222881,11415084,974935,8904950,2012573,5301203,1928327,12527971,11698842,1
5054012,961766,9422347,17364433,7689363,1498027,21115124,27008643,19693031,12427318,37662
772,6719214,13997121,12649386,1486332,835662,1511831,925889,24480821,38235666,8461491,246
6467,23180223,1572493,1129013,2311731,9986229,3128046,2150003,977589,39832676,604788,1666
1415,2026860,5108586,951967,36876511,1816849,9229686,29437215,967520,902723,646752,206043
8,2610169,3120500,18304177,3658745,7214616,9296716,20327284,11200836,13794770,17174351,46
13211,13446486,22719799,2119446,3423466,692514,23447410,34254073,3656608,35989942,9158514
,11692579,10964513,1105332,1982679,15282107,19019892,48986587,1541168,682119,4325082,1260
818,20277985,22599216,670468,3807096,6135983,651956,710361,19076977,12418993,18148817,645
7833,940458,20855311,2313001,11311751,1826770,2697489,1544999,1227591,3277311,24562677,30
752487,10461114,1171913,1558444,40071050,11104884,940838,5950676,13919456,1038645,8231270
,1435484,8580517,8043878,6676540,5282000,1565594,976467,35468932,1442270,1095615,1882217,
8757711,20138550,2373332,2525411,1918670,15021524,3478858,683182,4225887,32155397,9485563
,962692,10961204,7115587,24135981,23426056,19341288,2301106,7204915,11512137,13433616,460
67301,643524,1970521,522357,11430136,2372938,13962636,658812,2432339,12150720,1627237,515
44682,1697888,677112,7918236,1287634,3592414,29130570,25128302,32332342,1856448,634935,15
72453,17900178,4258133,15209250,681808,2416665,4572890,17928433,11295133,6867194,61782718
,16633982,1951729,6599713,4488379,23850835,44622815,2548735,2004522,36597494,15274664,257
93879,9009838,5722648,20146216,3092576,13300129,4167995,24821287,1091528,14034132,8546131
,37476517,984547,2048067,971505,1380910,48003651,14775532,2290227,11817739,14729542,14862
66,18995025,16365017,27470967,16239715,2251291,13848569,52846159,34590351,40815901,650201
,36721211,11175812,16456263,1518041,5678645,19741526,4214128,2346129,1830312,4003847,1041
2146,8833512,5738803,1107130,15888774,14473245,8275515,35970528,999196,3474030,2506702,14
475539,10853158,6169196,62157319,36759364,9659581,7527425,24480820,12275291,1435942,11364
21,5611580,4525748,41867639,4045942,19180540,2334846,16696799,2813585,10276421,24557530,4
0661944,2410997,4352600,19102226,12144370,6178304,3711944,1558743,17478456,20248349,18373
533,2055631,1809938,13506739,1191607,29658883,396797,20247919,4543937,13553192,5578858,12
302342,14608403,11137527,8137553,1181106,2813875,11385618,2061287,1764956,12543648,569341
6,8063067,2369214,8039925,1837674,12924176,2831405,2156329,4272973,7990760,7793159,172631
5,5740390,7623978,5080747,1245918,4692014,10641858,13837397,14498597,14498600,14498596,14
361543,13022766,10290213,7197397,17106098,17106091,17106095,17106097,17106099,17106100,17
106104,57722655,57722656,14040586,956448,7858843,4862570,6670019,8996959,7660439,18970065
,11389355,11671233,13358000,14083002,25427673,15787425,26137023,15136044,2485508,2638297,
5674754,5739371,5740261,5740281,5740342,5740348,5740351,5740370,5740272,2687913,15341214,
18636147,5740376,30566939,10143079,9733583,5320861,13400120,14077224,25999140,8395164,104
05926,397748,7087467,4131131,7267860,7479545,13624454,24535880,24718133,26296108,29985282
,3671942,8815928,26077244,4687231,6280224,19151210,19151211,19151212,19151216,19151219,19
151221,19151222,19151227,19151230,19151231,19151232,19151233,19151234,19151242,19151246,1
9151247,19151256,19151259,19151260,19151261,19151262,19151264,19151266,19151267,19151268,
19151274,19151275,19151277,19151278,19151279,19151282,19151283,19151285,19151286,19151287
,19151291,19151293,19151294,19151295,19151304,19151305,19151307,19151310,19151315,1915131
6,19151317,19151322,24681459,58218526,58218529,58218531,58218535,58218537,58218543,582185
44,58218550,58218551,58218552,58218555,58218556,58218559,58218562,58218564,58218565,58218
567,58218569,58218570,58218571,23496639,24337107,32231811,26153640,6555519,11671215,12202
909,12202920,12202921,13197058,13197060,13357958,13357999,13358006,13358007,13362079,1393
0710,13930754,14082997,14082999,14083001,14083005,14498604,15201532,16390494,16390516,163
90550,16390735,16390736,16390803,17668988,17669183,14593669,14593670,6198530,9830613,2030
9316,4256425,21448492,22466130,28886963,31223645,9638535,25838369,1170835,2832565,3437619
,5979355,6088172,6822759,11671234,14083006,14454089,21344418,21344422,21344423,21344427,2
1344436,21344437,21344439,21344442,21344444,21344446,21344447,30427050,12757810,1976348,4
095796,4692177,8085518,29254775,24308474,30717084,14480891,2944942,19070405,23797206,1332
5955,28887560,31059102,25714632,4710653,32317077,4291336,22019202,30250970,23032614,33241
89,3677826,32266569,6197299,18106717,18401477,8982747,4042278,8982746,12205902,31205875,2
3208869,7200460,12507318,18984180,24117177,31165856,1095815,18425227,23910161,23924341,28
826291,24465411,29108973,29195339,2699061,13357952,15014141,25727504,28811862,23402679,83
00058,1703989,7034523,20465046,23746737,23767542,32242694,32166198,16869319,22906805,2313
9578,24197155,28978269,14444932,23912983,24121239,32057099,4186267,4813558,7441577,980926
9,5161087,7556472,7635381,8703546,13034920,13163417,19791898,22744789,24926451,25122649,2
5392512,28702312,29594806,1979413,13256399,13256400,13256402,13256405,13256406,13256409,1
3256410,30132660,30132644,20887818,30132638,30132650,30132654,30132656,30132657,30132663,
30132665,31278754,1903239,11840692,6556762,6642558,13960143,523618,625580,647231,666437,6
68933,670332,967712,2398237,2494611,3469140,3678322,4748691,8764645,12355762,19151111,202
69994,21614526,25468073,39778003,62472817,8291588,1971560)

You might also like