-
Notifications
You must be signed in to change notification settings - Fork 0
/
Qn 11 - 15
208 lines (203 loc) · 6.53 KB
/
Qn 11 - 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
----------------------------------------
-- Measure: [Most Tournaments Played v2]
----------------------------------------
MEASURE 'Key Measures'[Most Tournaments Played v2] =
CONCATENATEX(
TOPN(
1,
ADDCOLUMNS(
'Players',
"@PlayerName",
'Players'[Given Name] & " " & 'Players'[Family Name]
),
'Players'[Count Tournaments]
),
[@PlayerName],
", ",
[@PlayerName], ASC
)
DisplayFolder = "Day 11 Most Tournaments Played"
---------------------------------
-- Measure: [Most Matches Played]
---------------------------------
MEASURE 'Key Measures'[Most Matches Played] =
CONCATENATEX(
TOPN(
1,
ADDCOLUMNS(
SUMMARIZE(
'Player Appearances',
'Player Appearances'[Family Name],
'Player Appearances'[Given Name],
'Player Appearances'[Player Id],
"@count",
COUNT( 'Player Appearances'[Tournament Id] )
),
"@PlayerName",
'Player Appearances'[Given Name] & " "
& 'Player Appearances'[Family Name]
),
[@count]
),
[@PlayerName],
", ",
[@PlayerName], ASC
)
DisplayFolder = "Day 12 Most Matches Played"
----------------------------
-- Measure: [YoungestPlayer]
----------------------------
MEASURE 'Key Measures'[YoungestPlayer] =
VAR YoungestPlayerTable =
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(
'Players',
'Players'[Player Id],
'Players'[Birth Date],
'Players'[List Tournaments],
"@YearofBirth", LEFT( 'Players'[Birth Date], 4 )
),
"@TournamentYear", LEFT( 'Players'[List Tournaments], 4 )
),
'Players'[Birth Date] <> "not available"
&& 'Players'[Birth Date] <> BLANK( )
) -- create table
VAR Age =
ADDCOLUMNS(
YoungestPlayerTable,
"@Age", INT( [@TournamentYear] ) - INT( [@YearofBirth] )
)
VAR Youngest = MINX( Age, [@Age] ) -- use min to find youngest
RETURN
Youngest & " years"
DisplayFolder = "Day 13Youngest Player"
---------------------------------
-- Measure: [Youngest Player Q13]
---------------------------------
MEASURE 'Key Measures'[Youngest Player Q13] =
VAR __Table =
ADDCOLUMNS(
'Player Appearances',
"@DateOfBirth",
LOOKUPVALUE(
'Players'[Birth Date],
'Players'[Player Id],
'Player Appearances'[Player Id]
),
"@MatchDate",
LOOKUPVALUE(
'Matches'[Match Date],
'Matches'[Match Id],
'Player Appearances'[Match Id]
)
)
VAR __Age =
CONCATENATEX(
TOPN(
1,
ADDCOLUMNS(
__Table,
"DaysBetweenAge",
DATEDIFF( [@MatchDate], [@DateOfBirth], DAY ),
"@PlayerName",
'Player Appearances'[Given Name] & " "
& 'Player Appearances'[Family Name]
),
'Player Appearances'[DaysBetween], ASC
),
[@PlayerName],
", ",
[@PlayerName]
)
RETURN
__Age
DisplayFolder = "Day 13Youngest Player"
--------------------------------------------
-- Measure: [Youngest Player in a Final Q14]
--------------------------------------------
MEASURE 'Key Measures'[Youngest Player in a Final Q14] =
VAR __Table =
CALCULATETABLE(
ADDCOLUMNS(
'Player Appearances',
"@DateOfBirth",
LOOKUPVALUE(
'Players'[Birth Date],
'Players'[Player Id],
'Player Appearances'[Player Id]
),
"@MatchDate",
LOOKUPVALUE(
'Matches'[Match Date],
'Matches'[Match Id],
'Player Appearances'[Match Id]
)
),
'Player Appearances'[Stage Name] = "final"
)
VAR __Age =
CONCATENATEX(
TOPN(
1,
ADDCOLUMNS(
__Table,
"DaysBetweenAge",
DATEDIFF( [@MatchDate], [@DateOfBirth], DAY ),
"@PlayerName",
'Player Appearances'[Given Name] & " "
& 'Player Appearances'[Family Name]
),
'Player Appearances'[DaysBetween], ASC
),
[@PlayerName],
", ",
[@PlayerName]
)
RETURN
__Age
DisplayFolder = "Day 14 Youngest Player in a Final"
--------------------------------
-- Measure: [Oldest Captain Q15]
--------------------------------
MEASURE 'Key Measures'[Oldest Captain Q15] =
VAR __Table =
CALCULATETABLE(
ADDCOLUMNS(
'Player Appearances',
"@DateOfBirth",
LOOKUPVALUE(
'Players'[Birth Date],
'Players'[Player Id],
'Player Appearances'[Player Id]
),
"@MatchDate",
LOOKUPVALUE(
'Matches'[Match Date],
'Matches'[Match Id],
'Player Appearances'[Match Id]
)
),
'Player Appearances'[Captain] = "1"
)
VAR __Age =
CONCATENATEX(
TOPN(
1,
ADDCOLUMNS(
__Table,
"DaysBetweenAge",
DATEDIFF( [@MatchDate], [@DateOfBirth], DAY ),
"@PlayerName",
'Player Appearances'[Given Name] & " "
& 'Player Appearances'[Family Name]
),
'Player Appearances'[DaysBetween], DESC
),
[@PlayerName],
", ",
[@PlayerName]
)
RETURN
__Age
DisplayFolder = "Day 15 Oldest Captain"