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: I wanna share a pro tip with you guys
2
00:00:02,000 --> 00:00:03,000
that I think is pretty cool
3
00:00:03,000 --> 00:00:06,000
and it's creating a rolling calendar.
4
00:00:06,000 --> 00:00:08,000
So in the case that we've just walked through,
5
00:00:08,000 --> 00:00:10,000
we loaded up a discreet set of dates
6
00:00:10,000 --> 00:00:12,000
because we only want to analyze the data
7
00:00:12,000 --> 00:00:14,000
that we have on hand.
8
00:00:14,000 --> 00:00:16,000
Now, in our particular case,
9
00:00:16,000 --> 00:00:18,000
we don't need to change that calendar.
10
00:00:18,000 --> 00:00:20,000
We won't need to pull in new data
11
00:00:20,000 --> 00:00:22,000
or analyze new information over time, right?
12
00:00:22,000 --> 00:00:24,000
Everything's fixed.
13
00:00:24,000 --> 00:00:26,000
But what if you were in a situation
14
00:00:26,000 --> 00:00:29,000
that you had to, what would you do?
15
00:00:29,000 --> 00:00:32,000
Maybe you've built a weekly report that you wanna refresh
16
00:00:32,000 --> 00:00:35,000
with data every day of the week
17
00:00:35,000 --> 00:00:37,000
and share with your colleagues, or your boss,
18
00:00:37,000 --> 00:00:38,000
or your client.
19
00:00:38,000 --> 00:00:40,000
Rather than creating a fixed calendar
20
00:00:40,000 --> 00:00:42,000
and updating it over time,
21
00:00:42,000 --> 00:00:45,000
we're gonna use some M code to create a calendar
22
00:00:45,000 --> 00:00:49,000
that will be based on the current point in time.
23
00:00:49,000 --> 00:00:51,000
So it'll act as a rolling calendar
24
00:00:51,000 --> 00:00:54,000
that evolves as time goes on.
25
00:00:54,000 --> 00:00:56,000
So I'm gonna lay out all the steps here in the slides
26
00:00:56,000 --> 00:00:58,000
and then we're gonna jump into Power BI
27
00:00:58,000 --> 00:01:00,000
and I'll demo what it looks like.
28
00:01:01,000 --> 00:01:04,000
So step one, this is gonna be a great time to test out
29
00:01:04,000 --> 00:01:06,000
that blank query option that I showed you
30
00:01:06,000 --> 00:01:08,000
a little bit earlier in this section.
31
00:01:08,000 --> 00:01:12,000
So we'll create a new blank query,
32
00:01:12,000 --> 00:01:13,000
and then in our formula bar,
33
00:01:13,000 --> 00:01:15,000
we're gonna generate a starting date
34
00:01:15,000 --> 00:01:18,000
by entering something that's called a literal.
35
00:01:18,000 --> 00:01:21,000
And you're gonna write it exactly as it's shown here
36
00:01:21,000 --> 00:01:23,000
with the hash mark, the word date,
37
00:01:23,000 --> 00:01:26,000
and then the starting date, whatever you choose,
38
00:01:26,000 --> 00:01:28,000
doesn't matter what the starting date is,
39
00:01:28,000 --> 00:01:29,000
but you wanna make sure
40
00:01:29,000 --> 00:01:32,000
that it's in this year, month, date format.
41
00:01:32,000 --> 00:01:35,000
So in the example we're looking at here on the slide,
42
00:01:35,000 --> 00:01:38,000
this would represent January 1st, 2020.
43
00:01:40,000 --> 00:01:43,000
So from there, you're gonna click on the fx icon
44
00:01:43,000 --> 00:01:45,000
which adds a new custom step,
45
00:01:45,000 --> 00:01:48,000
and you're gonna enter the following M code.
46
00:01:48,000 --> 00:01:50,000
Now, I know it looks like it's a lot,
47
00:01:50,000 --> 00:01:52,000
and we're not really gonna dig in
48
00:01:52,000 --> 00:01:55,000
and unpack how this formula is working.
49
00:01:55,000 --> 00:01:57,000
We're just gonna use this almost like a recipe
50
00:01:57,000 --> 00:01:59,000
to create our list of dates.
51
00:01:59,000 --> 00:02:02,000
So once you've added that formula,
52
00:02:02,000 --> 00:02:05,000
a list will populate in the query editor,
53
00:02:05,000 --> 00:02:07,000
and then we're gonna convert that list into a table.
54
00:02:07,000 --> 00:02:10,000
Once you've added that formula,
55
00:02:10,000 --> 00:02:13,000
a list will populate within the query editor,
56
00:02:13,000 --> 00:02:16,000
and we're gonna convert that list into a table,
57
00:02:16,000 --> 00:02:20,000
and then we'll format that column as a date.
58
00:02:20,000 --> 00:02:22,000
And then last but not least, if you want,
59
00:02:22,000 --> 00:02:24,000
you can add some more calculated date columns
60
00:02:24,000 --> 00:02:26,000
like we showed in our last example.
61
00:02:26,000 --> 00:02:28,000
You can always add years, months, week,
62
00:02:28,000 --> 00:02:31,000
whatever you really want or need
63
00:02:31,000 --> 00:02:33,000
using those add column options.
64
00:02:33,000 --> 00:02:36,000
But it's really as simple as that.
65
00:02:36,000 --> 00:02:37,000
Let's go hop over into Power BI,
66
00:02:37,000 --> 00:02:39,000
and we're gonna write out this formula,
67
00:02:39,000 --> 00:02:41,000
and I'll show you exactly how it works.
68
00:02:43,000 --> 00:02:46,000
All right, so we're back inside our AdventureWorks Report
69
00:02:46,000 --> 00:02:50,000
and we want to come to New Source, get Blank Query,
70
00:02:51,000 --> 00:02:55,000
and this opens up a brand new blank query for us.
71
00:02:55,000 --> 00:02:59,000
So for the sake of consistency, let's update our table name,
72
00:02:59,000 --> 00:03:00,000
and we'll call this Rolling Calendar.
73
00:03:02,000 --> 00:03:03,000
We'll lock that in.
74
00:03:03,000 --> 00:03:04,000
And then the next thing we wanna do
75
00:03:04,000 --> 00:03:07,000
is come up to the formula bar here, right?
76
00:03:07,000 --> 00:03:10,000
And our first step is to use the literal.
77
00:03:10,000 --> 00:03:14,000
So this is going to =# or pound
78
00:03:14,000 --> 00:03:19,000
and date and then open paren and 2023,1,1.
79
00:03:21,000 --> 00:03:23,000
So I'm gonna start this at the beginning of 2023.
80
00:03:24,000 --> 00:03:25,000
We'll hit Enter.
81
00:03:25,000 --> 00:03:26,000
And when you press Enter,
82
00:03:26,000 --> 00:03:31,000
basically this creates a single value for January 1st, 2023.
83
00:03:31,000 --> 00:03:34,000
So again, not super helpful on its own yet,
84
00:03:34,000 --> 00:03:38,000
but the next step is to click on the function button
85
00:03:38,000 --> 00:03:40,000
and we're gonna add a new custom step.
86
00:03:40,000 --> 00:03:42,000
And you can see here where it says source.
87
00:03:42,000 --> 00:03:44,000
This is where I'm going to type in
88
00:03:44,000 --> 00:03:47,000
that long M formula that I shared with you.
89
00:03:47,000 --> 00:03:49,000
And I'm gonna type this out fairly quickly
90
00:03:49,000 --> 00:03:51,000
but I'll kind of talk it out.
91
00:03:51,000 --> 00:03:54,000
So feel free to pause the video as needed.
92
00:03:54,000 --> 00:03:58,000
All right, so here we're going to start off with list.Dates
93
00:04:02,000 --> 00:04:06,000
and I will expand the formula bar here.
94
00:04:06,000 --> 00:04:08,000
All right, and the next piece that we want to add in here
95
00:04:08,000 --> 00:04:13,000
is source, and then Number.From open paren,
96
00:04:19,000 --> 00:04:20,000
DateTime.LocalNow.
97
00:04:25,000 --> 00:04:26,000
And then we'll do open close paren
98
00:04:26,000 --> 00:04:30,000
like the TODAY or NOW function in Excel.
99
00:04:30,000 --> 00:04:33,000
And we'll do - Number.From(Source), right?
100
00:04:37,000 --> 00:04:39,000
We'll come over, we'll add one more comma
101
00:04:39,000 --> 00:04:41,000
and Shift + Enter to return down.
102
00:04:41,000 --> 00:04:43,000
And our last piece here is we're gonna add
103
00:04:43,000 --> 00:04:47,000
in a duration (1,0,0,0), right, end paren.
104
00:04:53,000 --> 00:04:56,000
We've got our closing parentheses, right?
105
00:04:56,000 --> 00:04:58,000
We'll click enter to lock this in, and awesome.
106
00:04:58,000 --> 00:05:01,000
You can see that we now have a list of dates
107
00:05:01,000 --> 00:05:03,000
that are generated here.
108
00:05:03,000 --> 00:05:05,000
So kind of scrolling back up here
109
00:05:05,000 --> 00:05:08,000
without diving into exactly what this M code is doing,
110
00:05:08,000 --> 00:05:09,000
in a nutshell,
111
00:05:09,000 --> 00:05:14,000
what we're asking it to do is to calculate the current date
112
00:05:14,000 --> 00:05:16,000
and then compare that against the literal
113
00:05:16,000 --> 00:05:19,000
that we just created, which is our starting date, right?
114
00:05:19,000 --> 00:05:23,000
And then based off the difference between those two dates,
115
00:05:23,000 --> 00:05:27,000
I want you to create a list of all of the individual values
116
00:05:27,000 --> 00:05:30,000
where the duration is one day.
117
00:05:30,000 --> 00:05:31,000
So it's basically saying,
118
00:05:31,000 --> 00:05:35,000
give me a list at the daily granularity between those dates,
119
00:05:35,000 --> 00:05:38,000
the literal and the current date based on today, right?
120
00:05:38,000 --> 00:05:40,000
So when we press Enter,
121
00:05:40,000 --> 00:05:42,000
we can see that we have created that whole list.
122
00:05:42,000 --> 00:05:46,000
See that our start date is here on January 1st, 2023.
123
00:05:46,000 --> 00:05:51,000
And if I scroll down to the bottom here, keep going,
124
00:05:51,000 --> 00:05:54,000
I'm down to April 20th, 2023,
125
00:05:54,000 --> 00:05:56,000
which is the date that I'm actually recording
126
00:05:56,000 --> 00:05:57,000
this lecture right now.
127
00:05:57,000 --> 00:06:00,000
So the cool thing here is that if you come back tomorrow
128
00:06:00,000 --> 00:06:04,000
or next week, or in a month, and you refresh this query,
129
00:06:04,000 --> 00:06:07,000
all of those new dates will be added
130
00:06:07,000 --> 00:06:09,000
or appended to the end of this list.
131
00:06:09,000 --> 00:06:12,000
So that's basically what's going on here with this query.
132
00:06:12,000 --> 00:06:14,000
Pretty easy to write out.
133
00:06:14,000 --> 00:06:15,000
One thing to keep in mind here
134
00:06:15,000 --> 00:06:19,000
is that M is case sensitive, right?
135
00:06:19,000 --> 00:06:23,000
So if you did ld here for List.Dates,
136
00:06:23,000 --> 00:06:25,000
that would throw an error.
137
00:06:25,000 --> 00:06:27,000
So if you're running into those types of errors as well
138
00:06:27,000 --> 00:06:29,000
make sure that your syntax
139
00:06:29,000 --> 00:06:33,000
along with your capitalization is also correct, right?
140
00:06:33,000 --> 00:06:35,000
So the next thing that we need to do
141
00:06:35,000 --> 00:06:36,000
is we have this List Tools,
142
00:06:36,000 --> 00:06:38,000
contextual menu that's popped up,
143
00:06:38,000 --> 00:06:41,000
and we want to click Convert to a Table.
144
00:06:41,000 --> 00:06:44,000
So here from this window, convert to table, right?
145
00:06:44,000 --> 00:06:47,000
There's no delimiter, and we shouldn't have any errors
146
00:06:47,000 --> 00:06:49,000
so we'll press OK.
147
00:06:49,000 --> 00:06:51,000
We can see that we convert to a table.
148
00:06:51,000 --> 00:06:54,000
From here, we want to do our one final step
149
00:06:54,000 --> 00:06:56,000
is update our column name.
150
00:06:56,000 --> 00:06:57,000
Let's call this date.
151
00:06:57,000 --> 00:07:00,000
And then we also want to update the data type, right?
152
00:07:00,000 --> 00:07:02,000
And we can set that to a date.
153
00:07:02,000 --> 00:07:03,000
So that looks great.
154
00:07:03,000 --> 00:07:05,000
And what's cool here is this is ready to use
155
00:07:05,000 --> 00:07:09,000
just like the other date tables that we've imported
156
00:07:09,000 --> 00:07:14,000
as we can click here, add column, go back to date,
157
00:07:14,000 --> 00:07:18,000
and we can start adding in calculated fields like year.
158
00:07:20,000 --> 00:07:22,000
Go back, we could add start a quarter
159
00:07:25,000 --> 00:07:26,000
and maybe the last thing we want to do
160
00:07:26,000 --> 00:07:28,000
is add start a month, right?
161
00:07:31,000 --> 00:07:36,000
So in a few minutes with a little custom M code,
162
00:07:36,000 --> 00:07:37,000
we're well on our way to creating
163
00:07:37,000 --> 00:07:40,000
a scalable rolling calendar
164
00:07:40,000 --> 00:07:43,000
that is gonna update based on the current date.
165
00:07:43,000 --> 00:07:44,000
Now, one thing to keep in mind here
166
00:07:44,000 --> 00:07:46,000
is that for the purposes of this course,
167
00:07:46,000 --> 00:07:49,000
we don't actually need this rolling calendar.
168
00:07:49,000 --> 00:07:51,000
We're really gonna rely on the calendar lookup table
169
00:07:51,000 --> 00:07:53,000
that we've created instead.
170
00:07:53,000 --> 00:07:56,000
So feel free to keep this query or delete it.
171
00:07:56,000 --> 00:07:57,000
All right?
172
00:07:57,000 --> 00:07:59,000
So that's gonna wrap up your pro tip lecture
173
00:07:59,000 --> 00:08:01,000
on creating Rolling calendars.
13615
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.