Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,730 --> 00:00:06,220
Let's talk about two more types of columns that you can add from within the query editor index columns
2
00:00:06,250 --> 00:00:07,960
and conditional columns.
3
00:00:08,170 --> 00:00:12,770
So starting with index columns you'll find the option right here in the add column menu.
4
00:00:13,030 --> 00:00:20,650
And basically when an index column is it's a list of sequential values that uniquely identify each individual
5
00:00:20,650 --> 00:00:21,780
row of a table.
6
00:00:22,000 --> 00:00:29,470
Typically these start from 0 or 1 and they're most often used to create unique keys or IDs that can
7
00:00:29,470 --> 00:00:32,620
be used to form relationships with other tables.
8
00:00:32,950 --> 00:00:36,390
And I know we've been kind of hinting at this idea quite a bit.
9
00:00:36,460 --> 00:00:40,970
That's going to be covered in depth in the data modeling 101 section of the course.
10
00:00:40,990 --> 00:00:43,920
So in next call is super simple.
11
00:00:43,960 --> 00:00:47,200
Moving on to conditional columns these are a bit more interesting.
12
00:00:47,230 --> 00:00:51,660
You can find them right there above the index column option in the ad column tab.
13
00:00:52,030 --> 00:01:00,250
And basically these allow you to define new fields based on logical rules or if then conditions so example
14
00:01:00,250 --> 00:01:05,320
that we're going to be walking through is creating a new conditional column that we're naming quantity
15
00:01:05,320 --> 00:01:11,900
type and the way that we want to define quantity type is a function of the order quantity column.
16
00:01:12,040 --> 00:01:18,290
So we can tell power be-I for any row in our table where the order quantity equals 1.
17
00:01:18,370 --> 00:01:24,290
I want to set my quantity type equal to single item if my order quantity is greater than 1.
18
00:01:24,400 --> 00:01:31,120
I want to set my quantity type to multiple items and then you always have this kind of catch all value
19
00:01:31,120 --> 00:01:33,710
is false otherwise statement at the end.
20
00:01:33,730 --> 00:01:39,290
That's basically the value that you want your column to take in the case that all of the rows are line
21
00:01:39,320 --> 00:01:41,590
items above are false.
22
00:01:41,590 --> 00:01:47,770
So power is going to cycle through each row from top to bottom and if none of those conditions are met
23
00:01:48,340 --> 00:01:51,870
that otherwise statement is the value that's returned.
24
00:01:51,910 --> 00:01:57,800
So let's open up our Adventure Works report and see what this looks like in power be-I.
25
00:01:58,150 --> 00:01:58,450
All right.
26
00:01:58,450 --> 00:02:03,580
So I'm looking at the relationships you see the three tables three connections that we already have
27
00:02:03,580 --> 00:02:04,430
in place.
28
00:02:04,450 --> 00:02:06,480
We're going to go ahead and Attie forth now.
29
00:02:06,670 --> 00:02:13,360
So follow along we're going to get more data from the cxxviii and this time I want my adventure work
30
00:02:13,360 --> 00:02:19,640
sales 20:17 file and preview looks good.
31
00:02:19,750 --> 00:02:25,680
Let's go ahead and edit it to jump into the query editor and right off the bat.
32
00:02:25,800 --> 00:02:28,390
Let's simplify this table name a little bit.
33
00:02:28,430 --> 00:02:33,190
I'm just going to change this to A.W. sales 2017.
34
00:02:33,650 --> 00:02:39,420
Now you'll notice that I'm not adding the word look up to this table name just like I did with product
35
00:02:39,510 --> 00:02:46,170
customer and calendar and that's intentional because we're not dealing with a lookup table here we're
36
00:02:46,170 --> 00:02:49,910
dealing with something called a data or a fact table.
37
00:02:50,190 --> 00:02:55,260
And we're going to explain what that means in the data modeling section of course but to give you a
38
00:02:55,260 --> 00:02:56,620
quick teaser.
39
00:02:56,940 --> 00:03:02,370
Essentially we're looking at order quantities and order line items here with keys that will allow us
40
00:03:02,370 --> 00:03:08,060
to map those orders territories to customers to products.
41
00:03:08,130 --> 00:03:11,340
And if I scroll all the way over to dates.
42
00:03:11,610 --> 00:03:15,070
So no need to dive any deeper than that quite yet.
43
00:03:15,180 --> 00:03:20,460
Just put that in your back pocket because that will come into play in the next section of course.
44
00:03:20,460 --> 00:03:23,880
So why don't we go ahead and practice adding an index column.
45
00:03:23,880 --> 00:03:32,220
So we'll add column index and if I drop down that menu you can select to start from 0 or 1 or if you're
46
00:03:32,220 --> 00:03:33,070
feeling crazy.
47
00:03:33,090 --> 00:03:35,800
Can Start with any customer number you choose.
48
00:03:36,060 --> 00:03:42,510
In this case my keys or my ID columns typically start from 1 so we can choose that option creates a
49
00:03:42,510 --> 00:03:44,000
new column here at the end.
50
00:03:44,250 --> 00:03:49,800
Kind of interesting it formatted it as a decimal number which doesn't really matter but let's go ahead
51
00:03:49,800 --> 00:03:54,040
and make it a whole number just like the other columns here and a little shortcut.
52
00:03:54,060 --> 00:04:00,030
Instead of dragging it to the beginning of the table you can right click and use this move option and
53
00:04:00,030 --> 00:04:02,490
move it to the beginning just in one click.
54
00:04:02,490 --> 00:04:03,960
So there we go.
55
00:04:04,290 --> 00:04:10,200
Maybe this is something like an order ID that we want to use to kind of track each individual order
56
00:04:10,500 --> 00:04:12,320
in which case we could rename the column.
57
00:04:12,540 --> 00:04:17,150
But to be honest we don't need this ID or key column here.
58
00:04:17,160 --> 00:04:20,810
In fact it may just complicate and confuse things down the road.
59
00:04:21,000 --> 00:04:24,600
So I'm actually going to write click and remove this column.
60
00:04:24,600 --> 00:04:30,250
Now what's interesting here is that I've landed basically exactly where it started.
61
00:04:30,300 --> 00:04:33,720
This is the table in its current untouched form.
62
00:04:34,110 --> 00:04:40,110
But you'll notice that there are now seven steps in my applied steps here because even though I removed
63
00:04:40,140 --> 00:04:46,500
my index column that step was recorded and that step still exists here in the history of my applied
64
00:04:46,500 --> 00:04:47,190
steps.
65
00:04:47,370 --> 00:04:54,180
So what this means is that whenever this sales 20:17 connection is refreshed power be-I is going to
66
00:04:54,180 --> 00:04:56,630
run through all of these applied steps.
67
00:04:56,730 --> 00:04:58,540
It's going to add an index column.
68
00:04:58,710 --> 00:04:59,980
Change the type.
69
00:05:00,030 --> 00:05:06,570
Move it to the beginning of the table and then delete it which is really inefficient and downright silly
70
00:05:06,570 --> 00:05:07,880
when you think about it.
71
00:05:07,890 --> 00:05:14,310
So rather than just calling that day because I'm back at the correct table format the proper approach
72
00:05:14,310 --> 00:05:21,180
here would be to actually remove all of those steps back to before I even added the next column in the
73
00:05:21,180 --> 00:05:22,110
first place.
74
00:05:22,440 --> 00:05:25,020
And now nothing's changed with my table preview.
75
00:05:25,020 --> 00:05:31,190
This is it's original raw form but now I only have three applied steps instead of seven.
76
00:05:31,410 --> 00:05:36,630
So kind of an important nuance to keep in mind there and a good demonstration of how these applied steps
77
00:05:37,050 --> 00:05:38,490
are actually working.
78
00:05:38,840 --> 00:05:40,160
Now last a little demo.
79
00:05:40,170 --> 00:05:44,600
Let's go ahead and add a conditional column right here above index.
80
00:05:44,730 --> 00:05:52,320
This opens up my dialog box and we're going to name this column quantity type.
81
00:05:52,510 --> 00:06:00,130
And just like we talked about we're going to say OK for every row in this table if my order quantity
82
00:06:00,970 --> 00:06:10,030
equals the value of 1 then the output or the value that my quantity type column should take is a single
83
00:06:10,330 --> 00:06:13,460
item just like that.
84
00:06:13,470 --> 00:06:18,160
Now I can press this button to add new rule and it gives me an LS If line.
85
00:06:18,160 --> 00:06:23,530
So if this first row condition is not met then what's the next thing you check for.
86
00:06:23,770 --> 00:06:31,990
Well you check that order quantity is greater than 1 in which case my output or my quantity type column
87
00:06:32,910 --> 00:06:40,170
should equal multiple items and you could keep adding conditions here if you had more complex scenarios
88
00:06:40,680 --> 00:06:46,890
in this case what we have here is a fully comprehensive and mutually exclusive list of conditions.
89
00:06:46,950 --> 00:06:49,970
You don't have any rows with an order quantity of zero.
90
00:06:50,310 --> 00:06:54,540
And I sure hope we don't have any rows with a quantity of negative values.
91
00:06:54,540 --> 00:06:57,970
So that just leaves us with two possible options.
92
00:06:58,020 --> 00:07:01,510
You've ordered one thing or you ordered more than one thing.
93
00:07:01,770 --> 00:07:07,850
But that said as a best practice kind of rule of thumb I always put an otherwise value in here.
94
00:07:08,040 --> 00:07:13,530
So let's just say you know if something's crazy we've got some weird data that we weren't anticipating
95
00:07:14,020 --> 00:07:18,960
will just set quantity type to other and press OK.
96
00:07:19,590 --> 00:07:25,530
And there you go you've got our new column quantity type and see that it's taking values of either multiple
97
00:07:25,560 --> 00:07:29,550
or single item based on this order quantity column.
98
00:07:29,550 --> 00:07:36,450
And if we look at our drop down one thing call out here it does show that the only two items are the
99
00:07:36,450 --> 00:07:40,770
only two options in this column are multiple items and single item.
100
00:07:40,770 --> 00:07:44,420
You'll often see this little flag that says list may be incomplete.
101
00:07:44,610 --> 00:07:50,670
That's just telling you that power be I looked at a small sample of rows within that column in order
102
00:07:50,670 --> 00:07:52,710
to produce the list above.
103
00:07:52,710 --> 00:07:55,550
And that's just to save memory and processing power.
104
00:07:55,650 --> 00:08:01,130
But if you want power be out to check the entire column to make sure that this list is comprehensive.
105
00:08:01,230 --> 00:08:04,840
Just press the load more button and that flag goes away.
106
00:08:05,040 --> 00:08:11,370
And this confirms that this quantity type column that we just created contains two values multiple items
107
00:08:11,460 --> 00:08:12,730
and single item.
108
00:08:12,780 --> 00:08:14,140
So press OK.
109
00:08:14,640 --> 00:08:16,910
And that's just about all we need to do.
110
00:08:17,750 --> 00:08:24,670
So let's go ahead and enter our home tab and press clothes and apply.
111
00:08:24,680 --> 00:08:25,100
All right.
112
00:08:25,160 --> 00:08:28,810
Let's save our workbook and keep moving on.
11862
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.