Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,000 --> 00:00:02,000
Instructor: Alright, so we're doing well here
2
00:00:02,000 --> 00:00:04,000
and have already looked
3
00:00:04,000 --> 00:00:05,000
at some tools that allow us
4
00:00:05,000 --> 00:00:08,000
to perform data exploration in QA,
5
00:00:08,000 --> 00:00:10,000
conduct some basic table transformations,
6
00:00:10,000 --> 00:00:14,000
and manipulate tables with text and numerical tools,
7
00:00:14,000 --> 00:00:15,000
and in this lecture,
8
00:00:15,000 --> 00:00:18,000
I wanna talk about arguably one of the most important tables
9
00:00:18,000 --> 00:00:21,000
in the data model, the date table,
10
00:00:21,000 --> 00:00:22,000
and we're gonna check
11
00:00:22,000 --> 00:00:25,000
out some date-specific tools within the Query Editor.
12
00:00:26,000 --> 00:00:29,000
So, looking at the "Add Column" menu in our Query Editor,
13
00:00:29,000 --> 00:00:30,000
you'll see those date
14
00:00:30,000 --> 00:00:32,000
and time tools grouped here on the right,
15
00:00:32,000 --> 00:00:35,000
and these are pretty straightforward.
16
00:00:35,000 --> 00:00:36,000
You've got a few different options here,
17
00:00:36,000 --> 00:00:38,000
and one of the more interesting ones right
18
00:00:38,000 --> 00:00:41,000
at the top of the list here is the Age option,
19
00:00:41,000 --> 00:00:44,000
and that actually automatically calculates the difference
20
00:00:44,000 --> 00:00:48,000
between the current time based on today, or a Now function,
21
00:00:48,000 --> 00:00:51,000
and the actual date in each row.
22
00:00:51,000 --> 00:00:53,000
You have the "Date Only" tool,
23
00:00:53,000 --> 00:00:55,000
which basically looks at any field that might contain
24
00:00:55,000 --> 00:00:57,000
both a date and a timestamp
25
00:00:57,000 --> 00:00:59,000
and it strips out the time component
26
00:00:59,000 --> 00:01:02,000
and leaves you with just the date only.
27
00:01:02,000 --> 00:01:03,000
You also have your pretty basic set
28
00:01:03,000 --> 00:01:06,000
of date component functions like year,
29
00:01:06,000 --> 00:01:09,000
month, quarter, week, and day,
30
00:01:09,000 --> 00:01:11,000
and that just basically extracts individual components,
31
00:01:11,000 --> 00:01:15,000
or individual attributes, from the date field,
32
00:01:15,000 --> 00:01:16,000
and if you're selecting a field
33
00:01:16,000 --> 00:01:18,000
that has a timestamp as well,
34
00:01:18,000 --> 00:01:21,000
you'll also have similar time-specific options
35
00:01:21,000 --> 00:01:22,000
like hour, minute, and second.
36
00:01:23,000 --> 00:01:24,000
Two other ones that I wanna call
37
00:01:24,000 --> 00:01:27,000
out here are Earliest and Latest,
38
00:01:27,000 --> 00:01:29,000
and you'll see that those two are at the bottom
39
00:01:29,000 --> 00:01:31,000
of the list and they're actually both grayed out,
40
00:01:31,000 --> 00:01:34,000
and that's because we're in an "Add Column" menu,
41
00:01:34,000 --> 00:01:37,000
and both of these functions act just like statistics tools
42
00:01:37,000 --> 00:01:40,000
and they return a single value.
43
00:01:40,000 --> 00:01:42,000
So, to access those two options,
44
00:01:42,000 --> 00:01:45,000
you actually need to grab them from the Transform option,
45
00:01:45,000 --> 00:01:47,000
and as you might have guessed,
46
00:01:47,000 --> 00:01:49,000
the "Earliest" option is going to return
47
00:01:49,000 --> 00:01:51,000
the earliest date in the column,
48
00:01:51,000 --> 00:01:54,000
"Latest" is gonna return the last date.
49
00:01:54,000 --> 00:01:55,000
So, a quick note here,
50
00:01:55,000 --> 00:01:58,000
you'll almost always wanna perform these date operations
51
00:01:58,000 --> 00:02:02,000
from the "Add Column" menu as opposed to the Transform menu
52
00:02:02,000 --> 00:02:03,000
since most of the time,
53
00:02:03,000 --> 00:02:05,000
the goal is to actually build
54
00:02:05,000 --> 00:02:08,000
up new fields using these date components
55
00:02:08,000 --> 00:02:09,000
as opposed to overriding
56
00:02:09,000 --> 00:02:13,000
or transforming an individual date or time column.
57
00:02:13,000 --> 00:02:14,000
So, pro tip here,
58
00:02:14,000 --> 00:02:15,000
what you can actually do
59
00:02:15,000 --> 00:02:18,000
in Power BI quite easily is load
60
00:02:18,000 --> 00:02:21,000
up a table that contains a single set of dates,
61
00:02:21,000 --> 00:02:23,000
or you could create a date table from scratch,
62
00:02:23,000 --> 00:02:26,000
and then use these date tools to actually build
63
00:02:26,000 --> 00:02:29,000
out an entire robust calendar.
64
00:02:29,000 --> 00:02:31,000
So, that's exactly what I'm gonna show you how
65
00:02:31,000 --> 00:02:33,000
to do in a second, but first,
66
00:02:33,000 --> 00:02:35,000
let me give you a little sneak peek
67
00:02:35,000 --> 00:02:36,000
of what it's gonna look like.
68
00:02:36,000 --> 00:02:37,000
So, we're gonna start out
69
00:02:37,000 --> 00:02:40,000
with a single column containing dates,
70
00:02:41,000 --> 00:02:42,000
and then we're gonna apply some
71
00:02:42,000 --> 00:02:45,000
of those predefined date options using
72
00:02:45,000 --> 00:02:46,000
the "Add Column" tools
73
00:02:46,000 --> 00:02:48,000
in the Query Editor,
74
00:02:49,000 --> 00:02:51,000
and then we're gonna transform that individual column
75
00:02:51,000 --> 00:02:54,000
into an entire calendar containing additional fields
76
00:02:54,000 --> 00:02:56,000
like day of week, day of name,
77
00:02:56,000 --> 00:03:00,000
start of week, month, quarter, year, et cetera.
78
00:03:00,000 --> 00:03:01,000
Alright, so let's open
79
00:03:01,000 --> 00:03:03,000
up Power BI and we'll give this a shot.
80
00:03:04,000 --> 00:03:06,000
Alright, so if you're continuing along,
81
00:03:06,000 --> 00:03:08,000
we had left off in the Query Editor here,
82
00:03:08,000 --> 00:03:09,000
and we're gonna go
83
00:03:09,000 --> 00:03:12,000
and open up our sixth CSV,
84
00:03:12,000 --> 00:03:13,000
and we're gonna connect
85
00:03:13,000 --> 00:03:16,000
to our AdventureWorks Calendar Table.
86
00:03:16,000 --> 00:03:19,000
Alright, and the preview looks very straightforward.
87
00:03:19,000 --> 00:03:22,000
We have just a single column containing dates.
88
00:03:22,000 --> 00:03:23,000
So, let's click OK
89
00:03:23,000 --> 00:03:26,000
and we'll add this into the Query Editor, and again,
90
00:03:26,000 --> 00:03:28,000
let's keep our process consistent.
91
00:03:28,000 --> 00:03:30,000
So, the first two steps that we're gonna take,
92
00:03:30,000 --> 00:03:34,000
we're gonna update our table name to "Calendar Lookup,"
93
00:03:34,000 --> 00:03:35,000
and then we're gonna confirm
94
00:03:35,000 --> 00:03:38,000
that our column headers are updated
95
00:03:38,000 --> 00:03:39,000
and that the data type is set.
96
00:03:39,000 --> 00:03:41,000
So, we can see that we have date here
97
00:03:41,000 --> 00:03:44,000
and that our data type is set as a date also.
98
00:03:44,000 --> 00:03:47,000
Alright, so check and check. Everything looks great.
99
00:03:47,000 --> 00:03:50,000
Now, let's explore some of these different date tools,
100
00:03:50,000 --> 00:03:52,000
and I actually wanna start
101
00:03:52,000 --> 00:03:54,000
with the "Earliest" and "Latest" options.
102
00:03:54,000 --> 00:03:56,000
So, I'm gonna head up to the Transform menu,
103
00:03:56,000 --> 00:03:59,000
and then I'm gonna come over to my date tools here,
104
00:03:59,000 --> 00:04:02,000
and when I click "Earliest,"
105
00:04:02,000 --> 00:04:05,000
it behaves just like those stats functions, right?
106
00:04:05,000 --> 00:04:06,000
We transform the entire table
107
00:04:06,000 --> 00:04:09,000
into a single aggregated value,
108
00:04:09,000 --> 00:04:11,000
and we can see here that our calendar,
109
00:04:11,000 --> 00:04:15,000
or our "Earliest" date starts on January 1st, 2020.
110
00:04:15,000 --> 00:04:16,000
If I clear this out,
111
00:04:17,000 --> 00:04:20,000
head back to my Transform tab,
112
00:04:20,000 --> 00:04:22,000
and then we'll click "Latest,"
113
00:04:22,000 --> 00:04:24,000
this is going to give us the latest date
114
00:04:24,000 --> 00:04:25,000
in the calendar, right?
115
00:04:25,000 --> 00:04:28,000
So, this is June 30th, 2022, alright?
116
00:04:28,000 --> 00:04:29,000
So, we've got about two
117
00:04:29,000 --> 00:04:33,000
and a half years worth of data within our calendar table.
118
00:04:33,000 --> 00:04:35,000
So, let's close these steps out
119
00:04:35,000 --> 00:04:37,000
and we'll get back to where we started.
120
00:04:37,000 --> 00:04:40,000
Now, let's shift gears into actually adding columns, right?
121
00:04:40,000 --> 00:04:43,000
Because that's what the real value is here, and this time,
122
00:04:43,000 --> 00:04:45,000
I wanna create some new fields based
123
00:04:45,000 --> 00:04:47,000
on this date column.
124
00:04:47,000 --> 00:04:50,000
So, if I come up here to "Add Column,"
125
00:04:50,000 --> 00:04:55,000
and let's say we wanna add in the day name first, right?
126
00:04:55,000 --> 00:04:58,000
And again, you can see that these values are great out here
127
00:04:58,000 --> 00:05:00,000
because we're adding columns.
128
00:05:00,000 --> 00:05:03,000
So, if I click on "Name of Day,"
129
00:05:04,000 --> 00:05:06,000
we get a brand new column that's added.
130
00:05:06,000 --> 00:05:09,000
We have an applied step here, insert a day of name,
131
00:05:09,000 --> 00:05:11,000
and we see our column here, right?
132
00:05:11,000 --> 00:05:13,000
"Day name" for the column header name
133
00:05:13,000 --> 00:05:15,000
and then the data type is a text,
134
00:05:15,000 --> 00:05:17,000
and we could update this if we wanted to,
135
00:05:17,000 --> 00:05:19,000
but "Day Name" is actually pretty good,
136
00:05:19,000 --> 00:05:22,000
so we're gonna leave this as is.
137
00:05:22,000 --> 00:05:24,000
Another interesting piece here that I wanna show you is
138
00:05:24,000 --> 00:05:26,000
that the Query Editor actually has
139
00:05:26,000 --> 00:05:30,000
some very interesting week-related calculations, alright?
140
00:05:30,000 --> 00:05:33,000
So, if we head up here to Week, we can see week of year,
141
00:05:33,000 --> 00:05:36,000
week of month, start of week, end of week,
142
00:05:36,000 --> 00:05:39,000
and I wanna insert a "start of week" calculation,
143
00:05:39,000 --> 00:05:41,000
and as we can see here,
144
00:05:41,000 --> 00:05:42,000
as we look down when the start
145
00:05:42,000 --> 00:05:44,000
of the week is actually occurring,
146
00:05:44,000 --> 00:05:47,000
we can see that it happens on a Sunday, right?
147
00:05:47,000 --> 00:05:50,000
January 5th is the start of the week, on this Sunday.
148
00:05:50,000 --> 00:05:51,000
We skip down here,
149
00:05:51,000 --> 00:05:54,000
we see the 12th, it's a Sunday,
150
00:05:54,000 --> 00:05:57,000
so on 19th, the Sunday, so on and so forth, right?
151
00:05:57,000 --> 00:06:01,000
But maybe that's fine, but maybe you wanna update it,
152
00:06:01,000 --> 00:06:04,000
and to update it or customize the start of the week,
153
00:06:04,000 --> 00:06:06,000
it's actually not super intuitive
154
00:06:06,000 --> 00:06:08,000
and there are a couple of different ways that we
155
00:06:08,000 --> 00:06:10,000
could actually accomplish this, right?
156
00:06:10,000 --> 00:06:14,000
The first way is we could come up here to the Formula bar
157
00:06:14,000 --> 00:06:17,000
and we could type in and edit the M code here,
158
00:06:17,000 --> 00:06:19,000
or we can click this gear icon
159
00:06:19,000 --> 00:06:22,000
and edit the applied step directly
160
00:06:22,000 --> 00:06:24,000
from a window that pops up.
161
00:06:25,000 --> 00:06:27,000
Alright, so now that we're in
162
00:06:27,000 --> 00:06:30,000
this custom column window here, right,
163
00:06:30,000 --> 00:06:32,000
this just makes it a little bit more manageable
164
00:06:32,000 --> 00:06:34,000
to understand what exactly we're dealing with
165
00:06:34,000 --> 00:06:37,000
instead of trying to edit the M code directly
166
00:06:37,000 --> 00:06:38,000
within the Formula bar,
167
00:06:38,000 --> 00:06:42,000
and this date function, "Date.StartOfWeek,"
168
00:06:42,000 --> 00:06:45,000
has an optional second parameter, right?
169
00:06:45,000 --> 00:06:47,000
The first parameter is the date column that you wanna use.
170
00:06:47,000 --> 00:06:50,000
The second is the start,
171
00:06:50,000 --> 00:06:52,000
or the first day of the week, right?
172
00:06:52,000 --> 00:06:53,000
You can see it brought
173
00:06:53,000 --> 00:06:55,000
up here through the Intellisense option,
174
00:06:55,000 --> 00:06:58,000
and I know that if I type in "one,"
175
00:06:58,000 --> 00:07:01,000
that returns Monday as the start of the week.
176
00:07:01,000 --> 00:07:03,000
So, we'll click OK,
177
00:07:03,000 --> 00:07:04,000
and you can see
178
00:07:04,000 --> 00:07:06,000
that our "Start of Week" column has shifted, alright?
179
00:07:06,000 --> 00:07:11,000
So, 1/6, it's a Monday, 1/13, it's a Monday, 1/20,
180
00:07:11,000 --> 00:07:13,000
it's a Monday, again,
181
00:07:13,000 --> 00:07:15,000
so on and so forth.
182
00:07:15,000 --> 00:07:15,000
You can also see up here
183
00:07:15,000 --> 00:07:20,000
in the Formula bar that the one has been added to this code.
184
00:07:20,000 --> 00:07:22,000
Say we wanted to change this to starting on a Tuesday,
185
00:07:22,000 --> 00:07:25,000
we could update that to two,
186
00:07:25,000 --> 00:07:27,000
and then we see the column shift again,
187
00:07:27,000 --> 00:07:32,000
1/7 on a Tuesday, 1/14 on Tuesday, 1/21 on Tuesday, right?
188
00:07:32,000 --> 00:07:36,000
So, it's super easy to kind of update the start of the week.
189
00:07:36,000 --> 00:07:38,000
It's just not really intuitive at first.
190
00:07:38,000 --> 00:07:42,000
So, let's actually jump back in to the supplied step here,
191
00:07:42,000 --> 00:07:44,000
and while this is really straightforward,
192
00:07:44,000 --> 00:07:47,000
it's tough for people to kind of read this, right?
193
00:07:47,000 --> 00:07:52,000
Two or one isn't a very intuitive or readable format.
194
00:07:52,000 --> 00:07:54,000
So, our other option here is to come in
195
00:07:54,000 --> 00:07:58,000
and update this two to something a little bit more readable,
196
00:07:58,000 --> 00:08:01,000
like "Day.Monday, right?
197
00:08:01,000 --> 00:08:03,000
And that is going to show somebody,
198
00:08:03,000 --> 00:08:05,000
when they're looking at this code that, hey,
199
00:08:05,000 --> 00:08:08,000
the day of the week is starting on a Monday.
200
00:08:08,000 --> 00:08:10,000
We'll click OK, and again,
201
00:08:10,000 --> 00:08:11,000
we see that update back
202
00:08:11,000 --> 00:08:12,000
to Monday as the start date on the sixth,
203
00:08:12,000 --> 00:08:15,000
Monday on the 13th,
204
00:08:15,000 --> 00:08:16,000
so this is great.
205
00:08:16,000 --> 00:08:17,000
I want my week to start on a Monday,
206
00:08:17,000 --> 00:08:19,000
so I'm gonna leave this alone.
207
00:08:19,000 --> 00:08:21,000
Alright, so let's keep things rolling along here,
208
00:08:21,000 --> 00:08:24,000
and I wanna add in some additional date columns, like,
209
00:08:24,000 --> 00:08:26,000
let's add in start of month.
210
00:08:26,000 --> 00:08:30,000
So, if I come back up to my date tools, click on Month,
211
00:08:30,000 --> 00:08:32,000
and then click on "Start of Month,"
212
00:08:32,000 --> 00:08:35,000
I can see here I've got this "Start of Month" column,
213
00:08:35,000 --> 00:08:38,000
and on close inspection here, something seems off,
214
00:08:38,000 --> 00:08:40,000
and what we need to be really careful
215
00:08:40,000 --> 00:08:43,000
of is the column that we've selected
216
00:08:43,000 --> 00:08:46,000
to base our calculated columns off of, right?
217
00:08:46,000 --> 00:08:49,000
So, see how we were on the "Start of Week" column?
218
00:08:49,000 --> 00:08:51,000
When we look at the "Start of Month,"
219
00:08:51,000 --> 00:08:54,000
we're seeing the start of month is in December 1st,
220
00:08:54,000 --> 00:08:57,000
December 1st, December 1st, December 1st, December 1st,
221
00:08:57,000 --> 00:09:01,000
but our dates are actually in January, right?
222
00:09:01,000 --> 00:09:02,000
It takes us until the 6th
223
00:09:02,000 --> 00:09:04,000
of January to actually catch up and say, hey,
224
00:09:04,000 --> 00:09:07,000
the start of our month is actually in January.
225
00:09:07,000 --> 00:09:10,000
So, what we need to do is make sure we have
226
00:09:10,000 --> 00:09:12,000
the Date column selected,
227
00:09:12,000 --> 00:09:15,000
and then we can come over, go to Month,
228
00:09:15,000 --> 00:09:17,000
"Start of Month," and here,
229
00:09:17,000 --> 00:09:20,000
you can see the difference between the two, right?
230
00:09:20,000 --> 00:09:23,000
Now, we're correctly assigning the appropriate start
231
00:09:23,000 --> 00:09:26,000
of month based on the Date column instead
232
00:09:26,000 --> 00:09:28,000
of based on the start of the week.
233
00:09:28,000 --> 00:09:30,000
So again, this is something to really just keep an eye
234
00:09:30,000 --> 00:09:33,000
on as you're working through adding columns.
235
00:09:33,000 --> 00:09:36,000
If you have any sort of issues
236
00:09:36,000 --> 00:09:38,000
or errors within these calculated columns,
237
00:09:38,000 --> 00:09:40,000
make sure that you're basing everything
238
00:09:40,000 --> 00:09:42,000
off of the Date column.
239
00:09:42,000 --> 00:09:45,000
So again, we cleared those applied steps out.
240
00:09:45,000 --> 00:09:49,000
I'm gonna go back to my "Start of Month," and now,
241
00:09:49,000 --> 00:09:52,000
we've got this appropriately set up, right?
242
00:09:52,000 --> 00:09:56,000
All these starter months in January, we get into February,
243
00:09:56,000 --> 00:09:59,000
and it's starting appropriately there as well.
244
00:09:59,000 --> 00:10:01,000
Alright, so everything looks good now.
245
00:10:01,000 --> 00:10:03,000
Let's add in one more column here
246
00:10:03,000 --> 00:10:05,000
for our start of quarter,
247
00:10:07,000 --> 00:10:09,000
and again, we had that Date column selected,
248
00:10:09,000 --> 00:10:11,000
so our "Start of Quarter" values
249
00:10:11,000 --> 00:10:13,000
are good to go there as well.
250
00:10:13,000 --> 00:10:15,000
Alright, so this is a great start so far,
251
00:10:15,000 --> 00:10:17,000
and I think you're getting the idea
252
00:10:17,000 --> 00:10:20,000
of how quickly a calendar table can be built
253
00:10:20,000 --> 00:10:22,000
from a single column of dates,
254
00:10:22,000 --> 00:10:25,000
and what this calendar table will actually allow you to do
255
00:10:25,000 --> 00:10:27,000
is to filter and segment the values
256
00:10:27,000 --> 00:10:30,000
in a data set by any of these fields that we've created,
257
00:10:30,000 --> 00:10:33,000
and this is gonna be really helpful when we start using more
258
00:10:33,000 --> 00:10:37,000
of the analysis and visualization tools within Power BI.
259
00:10:37,000 --> 00:10:40,000
Alright, so for now, I think our calendar is good to go.
260
00:10:40,000 --> 00:10:42,000
We'll head back home.
261
00:10:42,000 --> 00:10:45,000
We'll click "Close and Apply" to save these changes.
262
00:10:47,000 --> 00:10:48,000
There we go.
263
00:10:48,000 --> 00:10:49,000
We've got our calendar lookup table
264
00:10:49,000 --> 00:10:51,000
that we just imported today.
265
00:10:51,000 --> 00:10:53,000
Alright, so there you have it.
266
00:10:53,000 --> 00:10:55,000
Those are our query editing date tools.
20927
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.