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: Let's talk about two more types of columns
2
00:00:02,000 --> 00:00:04,000
that you can add from within the Query Editor,
3
00:00:04,000 --> 00:00:07,000
index columns and conditional columns.
4
00:00:07,000 --> 00:00:09,000
So, starting with index columns,
5
00:00:09,000 --> 00:00:13,000
you'll find the option right here in the Add Column menu.
6
00:00:13,000 --> 00:00:15,000
And basically, what an index column is,
7
00:00:15,000 --> 00:00:18,000
is it's a list of sequential values
8
00:00:18,000 --> 00:00:21,000
that uniquely identify each individual row of a table.
9
00:00:21,000 --> 00:00:24,000
Typically, these start from zero or one
10
00:00:24,000 --> 00:00:25,000
and they're most frequently used
11
00:00:25,000 --> 00:00:27,000
to create unique keys or IDs
12
00:00:27,000 --> 00:00:30,000
that can be used to form relationships with other tables.
13
00:00:30,000 --> 00:00:31,000
And I know we've been kind of
14
00:00:31,000 --> 00:00:33,000
hinting at this idea for quite a bit,
15
00:00:33,000 --> 00:00:35,000
and it's something that's gonna be covered
16
00:00:35,000 --> 00:00:37,000
in much more depth in the intro
17
00:00:37,000 --> 00:00:39,000
to data modeling section of this course.
18
00:00:39,000 --> 00:00:42,000
So, index columns, they're super simple.
19
00:00:42,000 --> 00:00:43,000
Moving on to conditional columns,
20
00:00:43,000 --> 00:00:45,000
these are a bit more interesting,
21
00:00:45,000 --> 00:00:48,000
and you can find 'em right there
22
00:00:48,000 --> 00:00:51,000
above the Index Column option in the Add Column tab.
23
00:00:51,000 --> 00:00:54,000
And basically, these allow you to define new fields
24
00:00:54,000 --> 00:00:58,000
based on logical rules or IF/THEN conditions.
25
00:00:58,000 --> 00:01:00,000
So the example we're going to be walking through
26
00:01:00,000 --> 00:01:03,000
is to create a new conditional column
27
00:01:03,000 --> 00:01:04,000
that we're naming Quantity Type.
28
00:01:04,000 --> 00:01:07,000
And the way that we're gonna define Quantity Type
29
00:01:07,000 --> 00:01:10,000
is a function of the Order Quantity column.
30
00:01:10,000 --> 00:01:13,000
So, we can tell Power BI for any row in our table
31
00:01:13,000 --> 00:01:15,000
where the Order Quantity equals one,
32
00:01:15,000 --> 00:01:19,000
I wanna set my Quantity Type equal to single item.
33
00:01:19,000 --> 00:01:21,000
If my Order Quantity is greater than one,
34
00:01:21,000 --> 00:01:24,000
I wanna set my Quantity Type to multiple items.
35
00:01:24,000 --> 00:01:27,000
And then you always have this catchall value if false.
36
00:01:27,000 --> 00:01:30,000
So, that's basically, the value
37
00:01:30,000 --> 00:01:32,000
that you want your column to take
38
00:01:32,000 --> 00:01:34,000
in the case that all of the rows
39
00:01:34,000 --> 00:01:36,000
or line items above are false.
40
00:01:36,000 --> 00:01:38,000
So, Power BI is gonna go through and cycle through
41
00:01:38,000 --> 00:01:41,000
each of these rows from top to bottom.
42
00:01:41,000 --> 00:01:43,000
And if none of the conditions are met,
43
00:01:43,000 --> 00:01:46,000
then that otherwise statement is the value that's returned.
44
00:01:46,000 --> 00:01:49,000
All right, so let's open up our Adventure Works report
45
00:01:49,000 --> 00:01:52,000
and we'll see what this looks like in the Query Editor.
46
00:01:53,000 --> 00:01:55,000
All right, so at this point in the course
47
00:01:55,000 --> 00:01:56,000
we're getting pretty close
48
00:01:56,000 --> 00:01:58,000
to having all of our tables loaded.
49
00:01:58,000 --> 00:01:59,000
And in this lecture,
50
00:01:59,000 --> 00:02:01,000
we're gonna start working with our sales data.
51
00:02:01,000 --> 00:02:03,000
So, first thing that I want to do here is
52
00:02:03,000 --> 00:02:05,000
this query view here is getting
53
00:02:05,000 --> 00:02:06,000
a little bit cluttered for me.
54
00:02:06,000 --> 00:02:08,000
So, I actually wanna group together
55
00:02:08,000 --> 00:02:12,000
a bunch of these queries that we have disabled load for.
56
00:02:12,000 --> 00:02:14,000
All right, so I'm gonna select all of these queries
57
00:02:14,000 --> 00:02:17,000
by right click, Move To Group,
58
00:02:17,000 --> 00:02:20,000
and then create a new group here.
59
00:02:20,000 --> 00:02:23,000
I'm just gonna call these Demo Queries.
60
00:02:24,000 --> 00:02:25,000
All right, we'll click OK.
61
00:02:25,000 --> 00:02:27,000
And basically, what this does
62
00:02:27,000 --> 00:02:29,000
is it creates a folder structure
63
00:02:29,000 --> 00:02:31,000
within your query pane here.
64
00:02:31,000 --> 00:02:34,000
And again, it just really cleans this up.
65
00:02:34,000 --> 00:02:35,000
So, now we can see exactly
66
00:02:35,000 --> 00:02:38,000
the live queries here that we're working with.
67
00:02:38,000 --> 00:02:40,000
All of these other ones are still accessible
68
00:02:40,000 --> 00:02:42,000
and we could manage these
69
00:02:42,000 --> 00:02:43,000
and mess with them at a later date.
70
00:02:43,000 --> 00:02:45,000
But again, this kind of cleans things up.
71
00:02:45,000 --> 00:02:47,000
All right, so we're gonna make sure
72
00:02:47,000 --> 00:02:50,000
that we have our Other Queries folders selected here
73
00:02:50,000 --> 00:02:53,000
and then we're gonna connect to our sales data.
74
00:02:54,000 --> 00:02:58,000
And for this example, let's use the 2022 sales data.
75
00:02:59,000 --> 00:03:01,000
Our data preview looks great.
76
00:03:01,000 --> 00:03:03,000
It's pretty simple here.
77
00:03:03,000 --> 00:03:05,000
We've got order and stock dates,
78
00:03:05,000 --> 00:03:07,000
order number, some key columns,
79
00:03:07,000 --> 00:03:09,000
and then Order and Order Quantity.
80
00:03:10,000 --> 00:03:12,000
So, we'll add this into our Query Editor.
81
00:03:13,000 --> 00:03:17,000
The table is added in our Other Queries folder here.
82
00:03:17,000 --> 00:03:20,000
And again, let's follow those kind of first two steps.
83
00:03:20,000 --> 00:03:23,000
We'll check out these column headers,
84
00:03:23,000 --> 00:03:26,000
Orderdate, Stockdate, Ordernumber.
85
00:03:26,000 --> 00:03:30,000
We've got date, date, a text field.
86
00:03:30,000 --> 00:03:33,000
Our key columns are set up as whole numbers,
87
00:03:33,000 --> 00:03:35,000
which look great.
88
00:03:35,000 --> 00:03:36,000
And then same thing with
89
00:03:36,000 --> 00:03:39,000
our Order and Order Quantity values.
90
00:03:39,000 --> 00:03:41,000
The next thing that I wanna do
91
00:03:41,000 --> 00:03:45,000
is we will update our name to Sales Data 2022.
92
00:03:46,000 --> 00:03:49,000
And one thing to mention here is I'm specifically
93
00:03:49,000 --> 00:03:52,000
not adding in that lookup identifier here,
94
00:03:52,000 --> 00:03:55,000
because this is a different type of table.
95
00:03:55,000 --> 00:03:58,000
This is something called a fact table, not a lookup table.
96
00:03:58,000 --> 00:04:00,000
And we're gonna explain exactly what that means
97
00:04:00,000 --> 00:04:02,000
in the data modeling section of this course.
98
00:04:02,000 --> 00:04:04,000
But to give you a quick teaser,
99
00:04:04,000 --> 00:04:07,000
essentially, we're looking at order quantities
100
00:04:07,000 --> 00:04:09,000
and order line items here
101
00:04:09,000 --> 00:04:12,000
with keys that allow us to map those orders
102
00:04:12,000 --> 00:04:14,000
to things like our territories, to customers,
103
00:04:14,000 --> 00:04:18,000
to products, to our calendar table.
104
00:04:18,000 --> 00:04:21,000
And see here, if I scroll over to dates,
105
00:04:21,000 --> 00:04:22,000
we've got some different date fields
106
00:04:22,000 --> 00:04:25,000
that we can use to tie to that calendar lookup table.
107
00:04:25,000 --> 00:04:28,000
So, no need to really dive any deeper than that quite yet.
108
00:04:28,000 --> 00:04:30,000
Just put this in the back of your head,
109
00:04:30,000 --> 00:04:31,000
because it'll come into play
110
00:04:31,000 --> 00:04:34,000
in the next section of the course.
111
00:04:34,000 --> 00:04:36,000
So, at this point, why don't we go ahead
112
00:04:36,000 --> 00:04:38,000
and practice adding an index column.
113
00:04:38,000 --> 00:04:41,000
So we're gonna come up to our Add Column menu.
114
00:04:41,000 --> 00:04:42,000
Index Column, and you can see
115
00:04:42,000 --> 00:04:44,000
from here we have some options.
116
00:04:44,000 --> 00:04:47,000
We can start from zero or one.
117
00:04:47,000 --> 00:04:49,000
Maybe you've got some sort of crazy business use case
118
00:04:49,000 --> 00:04:52,000
where you need to start from a different Custom Number.
119
00:04:52,000 --> 00:04:54,000
Again, you can specify that,
120
00:04:54,000 --> 00:04:57,000
and with a specific increment as well.
121
00:04:57,000 --> 00:05:00,000
Generally, I like to start from one, and perfect.
122
00:05:00,000 --> 00:05:03,000
You see here, we've got a new applied step
123
00:05:03,000 --> 00:05:05,000
for Add Index column.
124
00:05:05,000 --> 00:05:06,000
So, let's say that we wanna see this
125
00:05:06,000 --> 00:05:08,000
at the start of our dataset.
126
00:05:08,000 --> 00:05:12,000
You can click a column header here, and you can drag it.
127
00:05:12,000 --> 00:05:13,000
The other thing that you could do
128
00:05:13,000 --> 00:05:15,000
to be a little bit more efficient
129
00:05:15,000 --> 00:05:17,000
is you could right click, come down to Move,
130
00:05:17,000 --> 00:05:18,000
and then move this column
131
00:05:18,000 --> 00:05:21,000
to the beginning of the table.
132
00:05:21,000 --> 00:05:23,000
So, now we've got our index column here,
133
00:05:23,000 --> 00:05:25,000
we've reordered the column.
134
00:05:25,000 --> 00:05:27,000
So we've got another applied step there as well.
135
00:05:27,000 --> 00:05:29,000
All right, so far so good.
136
00:05:29,000 --> 00:05:33,000
And maybe this column is something like an order ID
137
00:05:33,000 --> 00:05:37,000
that we wanna use to kind of track each individual order.
138
00:05:37,000 --> 00:05:39,000
In which case we could rename the column,
139
00:05:39,000 --> 00:05:43,000
but to be honest, we don't need this ID or key column here.
140
00:05:43,000 --> 00:05:45,000
In fact, it actually might just complicate
141
00:05:45,000 --> 00:05:47,000
and confuse things down the road.
142
00:05:47,000 --> 00:05:49,000
So, what I'm gonna do is
143
00:05:49,000 --> 00:05:52,000
I'm gonna right click and delete this.
144
00:05:52,000 --> 00:05:53,000
Now, what's interesting here is
145
00:05:53,000 --> 00:05:56,000
I've basically, landed exactly where I started.
146
00:05:56,000 --> 00:06:00,000
This is the table in its original kind of untouched form.
147
00:06:00,000 --> 00:06:03,000
All the same columns that we've started with
148
00:06:03,000 --> 00:06:05,000
and that we imported.
149
00:06:05,000 --> 00:06:08,000
But one of the things that you'll notice here is that
150
00:06:08,000 --> 00:06:11,000
I've actually got six different applied steps now
151
00:06:11,000 --> 00:06:15,000
and what's happened is when we've removed the column
152
00:06:15,000 --> 00:06:18,000
it didn't delete these other applied steps.
153
00:06:18,000 --> 00:06:22,000
So, if I click back to the Add Index column applied step,
154
00:06:22,000 --> 00:06:24,000
you can see that it's actually still here.
155
00:06:24,000 --> 00:06:26,000
So, the implications of this are that
156
00:06:26,000 --> 00:06:28,000
each time we refresh this dataset,
157
00:06:28,000 --> 00:06:31,000
or we add more data to it, or like something changes,
158
00:06:31,000 --> 00:06:33,000
Power BI is gonna run through
159
00:06:33,000 --> 00:06:35,000
all of these different applied steps.
160
00:06:35,000 --> 00:06:37,000
And that means adding the index column,
161
00:06:37,000 --> 00:06:40,000
reordering the column, and then deleting it.
162
00:06:40,000 --> 00:06:43,000
And that's just, honestly, a little bit silly and redundant,
163
00:06:43,000 --> 00:06:45,000
and it isn't efficient at all.
164
00:06:45,000 --> 00:06:47,000
So, what I'm gonna do here is I'm gonna
165
00:06:47,000 --> 00:06:50,000
delete these last three applied steps
166
00:06:50,000 --> 00:06:53,000
to remove that Add Index column work.
167
00:06:53,000 --> 00:06:56,000
And now we're back to our original dataset
168
00:06:56,000 --> 00:06:58,000
with our original three applied steps.
169
00:06:58,000 --> 00:07:00,000
So again, this is just kind of
170
00:07:00,000 --> 00:07:02,000
an important nuance to keep in mind,
171
00:07:02,000 --> 00:07:04,000
and it's just a good demonstration
172
00:07:04,000 --> 00:07:06,000
of how these applied steps are actually working.
173
00:07:07,000 --> 00:07:09,000
Now, our last little demo here
174
00:07:09,000 --> 00:07:11,000
I wanna create a conditional column
175
00:07:11,000 --> 00:07:14,000
and it's right there above that index column step
176
00:07:14,000 --> 00:07:16,000
and we get our dialogue box that opens here.
177
00:07:16,000 --> 00:07:18,000
And so, first things first,
178
00:07:18,000 --> 00:07:23,000
let's call this Quantity Type.
179
00:07:24,000 --> 00:07:27,000
And then we have our different inputs here
180
00:07:27,000 --> 00:07:28,000
for the conditional statement.
181
00:07:28,000 --> 00:07:30,000
And like we saw in our slides,
182
00:07:30,000 --> 00:07:33,000
we're gonna base this on our Order Quantity
183
00:07:33,000 --> 00:07:36,000
and we wanna set this when it equals to one.
184
00:07:36,000 --> 00:07:40,000
We want that output to equal single item.
185
00:07:41,000 --> 00:07:45,000
Click Add Clause to add an additional case here.
186
00:07:45,000 --> 00:07:50,000
So, if our Order Quantity equals one then single item,
187
00:07:50,000 --> 00:07:55,000
otherwise or Else if, Order Quantity is greater than one,
188
00:07:57,000 --> 00:08:00,000
we wanna return multiple items.
189
00:08:02,000 --> 00:08:04,000
So, at this point, we're gonna be all set
190
00:08:04,000 --> 00:08:06,000
for our conditional column,
191
00:08:06,000 --> 00:08:09,000
but in cases where you have more complex logic,
192
00:08:09,000 --> 00:08:12,000
you can continue to add new clauses here
193
00:08:12,000 --> 00:08:14,000
to create additional Else if statements
194
00:08:14,000 --> 00:08:16,000
for part of that conditional logic.
195
00:08:16,000 --> 00:08:19,000
In this case, what we have here is a fully comprehensive
196
00:08:19,000 --> 00:08:22,000
and mutually exclusive list of conditions.
197
00:08:22,000 --> 00:08:25,000
We don't really have any other rows in our table here
198
00:08:25,000 --> 00:08:27,000
with an Order Quantity of zero.
199
00:08:27,000 --> 00:08:29,000
And I sure hope we don't have any rows
200
00:08:29,000 --> 00:08:31,000
with a quantity of a negative value.
201
00:08:31,000 --> 00:08:34,000
So that really leaves us with just two possible options.
202
00:08:34,000 --> 00:08:36,000
You've either ordered one thing
203
00:08:36,000 --> 00:08:38,000
or you've ordered more than one thing.
204
00:08:38,000 --> 00:08:41,000
So, that said, as a best practice,
205
00:08:41,000 --> 00:08:44,000
I always like to have an Else clause.
206
00:08:44,000 --> 00:08:47,000
So, if either of these two conditions aren't met,
207
00:08:47,000 --> 00:08:50,000
we're gonna say Else Other.
208
00:08:50,000 --> 00:08:53,000
And again, this is just a great kind of catchall
209
00:08:53,000 --> 00:08:55,000
in case something really strange or weird
210
00:08:55,000 --> 00:08:59,000
or unanticipated happens within the dataset, we're covered.
211
00:08:59,000 --> 00:09:00,000
We'll be able to flag that.
212
00:09:00,000 --> 00:09:02,000
So, click OK.
213
00:09:03,000 --> 00:09:05,000
And you can see here in the Quantity Type column
214
00:09:05,000 --> 00:09:07,000
that we're getting our values
215
00:09:07,000 --> 00:09:09,000
of multiple and single returned.
216
00:09:09,000 --> 00:09:12,000
We can click the column header here
217
00:09:12,000 --> 00:09:15,000
and we can see multiple item and single item.
218
00:09:15,000 --> 00:09:17,000
One thing to notice here is that
219
00:09:17,000 --> 00:09:19,000
you've got this kind of warning flag here
220
00:09:19,000 --> 00:09:21,000
where it says, "List may be incomplete."
221
00:09:21,000 --> 00:09:24,000
What's happening here is that when you see this flag
222
00:09:24,000 --> 00:09:26,000
it's just Power BI telling you that,
223
00:09:26,000 --> 00:09:29,000
hey, I only looked at a sample of rows within the column
224
00:09:29,000 --> 00:09:31,000
in order to produce this list above.
225
00:09:31,000 --> 00:09:34,000
And this is really just Power BI's way
226
00:09:34,000 --> 00:09:36,000
of saving some memory and processing power.
227
00:09:36,000 --> 00:09:38,000
But if you want Power BI to check
228
00:09:38,000 --> 00:09:42,000
the entire contents of the column, click Load More.
229
00:09:42,000 --> 00:09:44,000
And that kind of forces Power BI
230
00:09:44,000 --> 00:09:47,000
to scan all of the values within the column
231
00:09:47,000 --> 00:09:49,000
instead of just a preview.
232
00:09:49,000 --> 00:09:50,000
All right, so this confirms
233
00:09:50,000 --> 00:09:55,000
that we have just two Quantity Types, multiple and single.
234
00:09:55,000 --> 00:09:56,000
So from here, we'll click OK.
235
00:09:57,000 --> 00:10:00,000
And that's just about all we need to do here.
236
00:10:00,000 --> 00:10:02,000
So, we'll head back to our Home tab.
237
00:10:02,000 --> 00:10:05,000
We'll click Close & Apply,
238
00:10:05,000 --> 00:10:08,000
and then we'll make sure to save this workbook.
239
00:10:08,000 --> 00:10:10,000
So, we've got our sales data 2022
240
00:10:10,000 --> 00:10:13,000
loaded into our model, and we'll keep moving on.
18988
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.