CT7 1
CT7 1
2024.05.29 수 오전 9:22 ・ 83 분 29 초
송인영
The file that we will use to connect to this new data set.
We shall go through again the connection because it goes too fast lack sign and so I want to replicate
that but please be ready as we have a lot of things to do.
So two, three minutes we start
now first of all, we want to connect to a new data set write a pretty simple measure and then think
about it because we need to
okay so we open an empty pixel file as always, it is completely empty there is nothing in it.
We will use this file to connect to our data set 1 import the data and create our data model and the
table, the power TU table.
So if we follow the usual steps, you will see that in PBI everything will be easier.
This is the last time we used power field from now on at the end of the lecture, we use power VI for the
rest of the course.
Now fire
it's going to connect to data data get data from file from Excel Worklo if you have a different layout, it
might be new, quiting prone work group or whatever.
You need to find these things problems just raise your hand and that will help you.
So you want to get data from this Excel file, which is a more complex file we're starting using now with
more tables you want to locate the file, the data set you want you downloaded
okay if I can
data set the one. So we are connecting to that set of data is power query connecting to that file we want
to select multiple items and get our one P table sales and four dimensions calendar, customer product
and sales territory.
That's exactly what we did last time but we want to redo that in case you missed anyth
okay now we should transform the data but we don't have time to do that.
We've already seen how we can kill one column or something like that.
We don't have time for this so we go ahead but please do not click load directly because this is Excel.
If you click load, Excel will decide whether to load the tables in classic Excel tables or inside power fields.
So we want to be sure that we give the right instructions.
So I want to select this side arrow you have here and select Load tube
whenever you have this ellipses here that means that Excel is waiting for your input before proceeding.
So we click this load too and now we can say the settings good one These are the set things you want to
cook only create connections.
We don't want any classic Excel tables and load to power people.
Once you click okay now you're loading the data inside the power filler
okay so now the data has been loaded we don't see anything.
The reason is that we didn't load the results into an Excel table.
We loaded them into power tables so there is nothing here.
But if you want to take a look at the data, we could kill the increasing connections.
If you want to rese that you go to Data Queries and Connections.
So with a double crick you can step in power query if you need but we shall not do that.
and then you select this mana drop down list you select come Adds and now you select go You want to
flag this power fuel for Excel once you flag that, you want to click Okay and the power fuel is already
here Can you notice that's right?
Okay okay now we can go to take a look at the data we loaded through Power Quer.
If you click on Manage Yeah if you click on Manage and not on Health, you take a look at the database
which is behind the curtain.
I will magnify now so you can see better one doing and now we need to create the relationships.
in sales customer key from customer connected with customer key in sales.
Another one too many connection we go ahead with the product key connected with the product key in
sales
and sales territory key connected to the sales territory key in sales again.
So you see here there is no composite key.
Each table has its own primary key which is the natural situation in case anyway, you don't have this.
Now you know, you can create a composite key like we did in data set future.
Okay so this is the data model that will answer the request of the pillo table.
So we shall ask that power pillo table something that power pub table will drive our request to the data
model.
You get the necessary information and we say fill itself with the data in order to create a power pivot.
Remember, you need to launch the pivot from here.
It doesn't save powered people but if you launch it from classic Excel, you see no data classic Excel
cannot reach this data.
So we need to launch this from within the power fueled window pie table.
And if you want to be sure you didn't get it wrong, it must not ask you where the data is.
It will only ask you where to put the report.
So you can select the existing worksheet if you want click OK.
There will be a pilot table right here.
This is indeed a power pilot and you can see that because all the tables are listed.
Be careful about these details.
If you find yourself for any reason in the active tab, it might be you only see a subset of the fields, those
involved in the appeal table.
So make sure to be here in all whenever we broached it.
If you don't find something typically for some reason you are here
Now if there are issues, please raise your hand because if you lose me this lecture, we are really in a bad
situation.
So any problems, please ask me the solution.
Don't disturb your neighbor.
So you are in two not listening and we get a problem.
Yes, I can't even hear you
go for forward in doing what you have just done because it's slowing something but I don't know what it
is.
We launch it and
okay so now we create a measure because we said that in the value section we only put measures
explicitly written in dux and we start with a measure we already discussed Monday the last lecture was
made Monday which is the count world measure.
We want to calculate the number of votes for each color.
So in general the measure is not by color.
It is give me the number of rows of the sales table, which is count rows sales.
Remember this
okay now we need to start understanding a little better what we're seeing and I will do the following.
I will now recall here the code of the measure.
Filters, columns or slices belong in two dimensions with respect to the rule.
So this filter is propagated as I explained on Monday to the sales table.
And now you see how many rows are exposed from the sales table.
The number of rows visible is 9,843 Okay so the code is executed always.
The code that is executed is always that one.
Now we need to start with the first bital question How is it possible that I execute the same code?
I have executed the same code 9 times Why do I get 9 different results?
I execute Crose sales and he gives me 9,843 then I execute again cross sales and I have 3,009,000 V again
30,926, 28,000,919 and so forth.
The code is always count Rose sales.
If I get a different result, something must be changing but the code is always cro Cal.
So what is changing? How is it possible to get different results?
If it's obvious, that's okay certify the obvious with me please.
okay okay so that I hope that gives the idea that we need to understand a little better about these filters
because now we will play a little bit in this model.
So let's recap what a filter is.
A filter is a restriction on the values of a column.
You can also say the same thing like a filter is a list of values for that colum.
I can say that the product color needs to be black, blue surg that's a filter.
I allow only three values for that color or I can say a filter is product color equals black
it's still one filter and the values allowed is just one value.
So you can allow all the values.
In that case there is no filter at all or you can unload a subset of the bodies or you can apply one body
that you want and the result would be that there would be no rows.
I can say that the filter needs to be or that the color needs to be orange.
If I apply that filter, the result would be no rows.
So the restriction
So consider as the list of all the filters that are applied to the model before doing a calculation which is
typically a method one or more methods who create these filters.
We create the filters when we put color in rows.
Again, we asked to generate the list and to apply each value singularly as a filter to that column.
And after that it will go calculating whatever we have in the body section.
So let's try to describe the filter context in correspondence of one color or to the grand total.
This is the filter context in corresponding on that calculation I don't see therefore the cross filters that
are generated due to this because if I select, if I impose that the color is black, I have a filter only on the
product color.
But we know that this generates a cross filter on the product he the primary key that will be translated
into the product key in sales but this is not a direct filter.
So
the relationships propagate filters and cross filters but in the filter context I only see the filters directly
applied to columns.
So this is the only future direct applied to a column in corresponding of the calculation that gives 9,843
as a result.
Now how should I describe the filter context at the grand total with the same technique?
In this state in which I am the chief of state you can do whatever you want and I want to write a book
listing everything that is possible to do.
You understand that this list will be pretty long, right?
Maybe it would be an infinite book but there is a way to make this book very short.
Anything is possible it's much shorter and it doesn't need to be updated because if I list all the things you
can do one day you invent a new crazy thing you want to do.
I need to add it to the list.
in an empty filter context I see everything because there is no restriction in any column.
Okay so in the ground total we say the filter contact is amplitude
Now how many roles are visible in the sales table under the filter context product color equals black?
I will phrase the question when I have as a filter, product color equals black.
How many rows does the sales table expose?
It's obvious can you please say that?
Okay you have it in front of you and you realize that which is good.
I just wanted to be sure that I was clear.
So this is telling me
how the cells table changes due to the filters.
You can see exactly how many rows are exposed for the calculation in the different filters that we apply.
Now suppose that we get now a question that we need to solve that will imply the usage of different
kind of table functions.
There are two main kinds of functions.
One is the scalar functions.
Up to now we have always used scalar functions.
What is the definition of a scalar function?
It's a function whose output output I didn't say input so we don't care about the input but the output is
a single value.
It can either be a number, a text, a date, a logical value, whatever you want.
A single value example of a scalar function sum another example okay divide is another example.
What about Cros?
We are able with this with this pil table we are now seeing the number of rows of the cells table
therefore the number of transactions by each color.
Now suppose that a question comes from the boss that says well, okay, interesting but now I would like
to see for each color the percentage of transactions that are coming from customers that have boxers as
education.
In the table customers, we have the list of customers
The boss wanted to have the 3000 ratio, the 9,000 and something we were seen before okay can I get
those results with this technique?
The answer is no because now I'm filtering the entire pot table only for batchelor customers.
So I'm losing the total rows of the black color which is 9,000.
Therefore I cannot answer the question in this way.
So those rules are for black products but I want to do a further selection, the batcher of customers.
So what I need to do it's okay give me the 9,000 rows.
That's okay I have them they are in the sales table but what I need to do is take each row of the sales
table and check whether the customer has an English education equal to Buchros.
Okay so this time I cannot give to Countros the cells stable because if I need to cancel the cell stable, the
cell stable is filtered only by the color.
Now filter is a table function and as any function, you can see that as a black box that's an input, a table
and an output another table.
What filter does is it scans the input table by row by row and in each role, it verifies a condition that we
have to specify.
If that condition is met for that row, that row will be in the output.
If that condition is not met, that row will be not in the output payable.
So what do we need to give?
Filter is a table to scan and then a condition to check.
Okay
so the number of rows of the output function will be either equal to the input to the number of rows of
the input function all will be lower.
One will be equal basically one there is no future when the condition is met in any row.
Okay remember that in reality filter doesn't filter to make it very clear.
So Microsoft is really helpful in this.
They should have called it selective.
So don't think about filter like a function that creates a filter like when you put something in rows in a
pivot table, the filter is going robe around a table and selecting the rows that match the condition which
is totally nothing but filtering.
So forget the filter I know the name is horrible.
They should have called it select but they told me, oh, it's already in sequel and I said, big deal you called
it filter and it doesn't filter but what happened?
So
I cannot write directly sales otherwise I'm just mimicking the transaction form.
This is a table. So that would work perfectly because Crose wants a table but if I do this, I'm giving to
CROS a sales table filtered only by color.
That's not what I want. Of course this will be 9,843 rows if we think about this context here but those
include any customer.
We want to do a selection on the customers.
To do a selection before giving the table to counts, we need to use an external filter condition.
So filter open parenthesis you see that filters is asking for a table and a filter expression, a condition.
Now the table is sales.
What is the condition? The condition is that education is equal to BLS, right?
English education equals to bargels.
Now before writing that, let's try to write something simpler.
Suppose that I want to select only the rows in sales in which what do we have here?
A France type I think okay which the order quantity let's say the order quantity needs to be bigger than
two.
I can look for order quantity.
You see that I see the field sales order quantity
and I can say filter sale cells of the quantity bigger than two Okay so that works and we could close the
palanthas but the condition that we want to impose is not on the order quantity.
In which field do I have to put a condition?
English education? Let's look for this English education.
I can't find it.
that goes to the customer table that is through the customer number which is unique in the customer
table and give you the blood education level of the unique customer in the current road.
To do this, we need to open to use a information function called related.
So if we type in other words, if, if you want to put a condition through sales on a column on the sales
table you are on, let's say a column on the sales table you don't need anything.
You can type it and that's it.
If you want to iterate a table like S but the condition you want to put it's in a related table in a table that
is connected, you need to use this keyword related.
And now you have the chance to put a condition on columns that belong to another table.
If you open related, you see that now you see all the columns of all the tables.
Are you surprised? Think carefully about that sales is the many side of all the one to many relationships
we have.
So if you are in a single row in sales, you have a single row in customer because in each row itself you
have a single customer and customer is the trial of the customer table.
You have a single row of the product table because in each row in sales there is one product.
The product is the key, the primary key of the product table and also from the calendar.
So in reality the F table can access directly any column of any table.
It's enough that there is a relationship.
So now we can say relation.
We can look for English education.
Now we find it
English education. Now the most important thing is closing in immediately related condition.
So related color closed and now we need to say equals to Baxlors.
Don't forget the S at the end and that's our code
shift. And then you can use tab in order to indent the CRB.
Now here works horribly.
Corbi is much better.
I'll phrase the question how many rows are visible in the cells table when we do that calculation note
wrong answer What are the filters applied to the model?
How many filters do we have in that calculation one or more than one only one and what is the filter?
No, there is no filter with the English education I told you, filter doesn't filter.
I only have a filter on the color.
The only filter applied to the model is product color equals black.
So that measure will always give you the number of rows visible of any table under certain fils you have a
question
because this measure will give us always the same result in any context because it needs to give us this
denominator.
I call it technical measure because you need to hide it to the customer because if the customer finds it
like it happened to me, it takes the phone and calls you.
Oh, there is a matric that doesn't work.
It's not that it doesn't work it's, you don't understand it so you should not see that.
That's why we call it technical mat.
So now we will create a measure that returns always the total number of rows of the cells table.
In order to do this, we need to use another table function.
In fact, we have an issue.
Now I asked you how many rows are visible under the context of the color equals black because this
should now point to the problem How can I recover 60,398 rows if the filters show me only 9,000 rows In
the example of the product black, I see 9,000 rows 9,800 okay with filter I can reduce that.
But in this case the relationship between the input table and the output table is the following.
The output table will be the input table evaluated in absence of filters.
I repeat again, I give to this function a table with a filter applied.
This function will return me to the table without any filters.
It will ignore any filter applied to the table in input and provide me always in output the entire table no
matter the filters applied.
It is still a Campros.
Again, I cannot use sales because if I simply say sales, we know what we are doing.
We are recreating the transaction matter and I cannot use filter sales because that would reduce the
rolls.
I don't want to reduce the rolls I want to increase the roads.
So I need to give as input all sales.
Let's check again we are understanding or that I am able to be to explain what I'm wanting to explain.
Let's consider again this context here.
How many roads do I see in this table?
How many B no, no, no in this concept it doesn't depend 9,000 perfect this number but I'm not giving
this to countl.
I'm giving this table to crose How many rolls do I have in this table?
600,398? Very good but remember that the cells table still has 9,843 rows.
It's always the same number of rows in any calculation.
So now we can check the formula the formula works look okay and we get a crazy calculation that can
either seem wrong.
In fact, if you remember when was the time that we had always the same body, try to remember what
happened when we were browsing by sales area we had no relationship between customer and sales.
I brought my cell set and we get always the same amount of cells in each continent.
The problem in that case was that there was no relationship between the tables.
So I was applying a filter on the sales area but this had no impact in sales because there was no
relationship.
So this result
usually it's perceived as wrong because it's the typical result you get when you filter a table you make a
calculation on another table there is no relationship.
So the calculation on the other table is independent on the filter that you do.
If you disconnect the product table from sales, you will see transaction would be always 600,398 but in
that case it's a mistake because I'm not filtering, I'm not using relationship.
In this case that's what I want okay so it looks wrong
this time I will leave you trying to do that on your own of course in a few minutes.
Then we see the solution and we'll go into the break.
It's also late afternoon so we are all tired.
I understand that. So look at what happened when we went from transactions to all transactions.
Transactions changes in every world color by color all transaction does not and it seems as the total of
the transactions
You want to ignore the filters from the color but you still want to inject the selection on the you can do
that using filter and all is just a way to try to understand how you can use them.
That will help you fixing the concept.
There is always somebody that does it that makes it.
So I'm just waiting a few minutes.
Some of you will get there which is very important.
Then we will do it together.
So please try to solve this for you can name the measure something like all transactions, buchelors
because it's the same value like the old transactions but it's focused on buchers.
in a minute I will give you a first hand because I know it's a bit confusing at the beginning and I'll suggest
don't try, don't start from scratch.
There are two measures that are already there either you start from all transactions and you already
have the same value everywhere.
The point is that you need to focus that value only on the BCHS.
That's one approach. Or you can start from the
transactions to butchers which has a different value everywhere but it's already restricted to
transactions.
So it's enough to ignore the filter on the color either way you get to the same result.
I suggest you don't start from scratch.
We don't have to reinvent the wheel every time we did the ready calculations that are similar take one of
those and try to modify them in order to get what you want.
Remember that you need to inject the selection on the customers
but you don't want to start from the sale from the transaction of that particular color.
You always want to start from the total amount of transactions, which means always starting from
600,398 and then inject the selection of the customer.
In my view, it's better to start on the transactions to bers there you just need to ignore the filters on the
sales table and the solution is done.
But a student last year told me that to him starting from all transactions was easier.
So maybe it's easier for you.
I don't know either. I don't care.
The result is what matters.
Each of us reasons in different ways
again. If you start from the transactions to bachelors, you take that code you already have the selection
on the Bacheler customers.
So the only point that you need to do is ignore the filter on the color.
So the filter condition in the measure should be on sales or something else.
If you have a filter on sales, you start from the color black from 9,000 and you go to 3000.
If you start from 300,970 for the blue, you go to 1019 1.
To make it work, you always need to start from 16,000,398 rows.
So take the code of the transaction to Buchers and make sure that filter iterates always the entire sales
table.
What is the function that returns to the entire cell stable?
All so practically I wrote the magic try to fix it yourself.
Instead of going on sails which is filtered by the color, you need to go on a table that doesn't feel that
filter.
So you need to protect sails with something that ignore the filters on the column and you will see that
everything works magically.
If you're done, please let me know dam I will show you the reasoning that you can do.
If you reason in another way that's okay until when you get to the same result.
Let me do the reasoning starting from transactions to bots.
If I want to get the total, I don't need to iterate only those rows.
I want to iterate all the rows.
So instead of iterating sails that is filtered by color, I need to protect it from the filter on the color.
I want always to start from 60,000 rows.
If you do this slight modification, slight doesn't mean simple I know it's difficult but now this shows
always 60,000 rows.
And when I start from 60,000 rows
As I told you, this one way of reasoning is not the only one and I will show you how to reason to get to
the same results starting from the old transaction met book one.
I still haven't saved it.
Okay now how could I have do the reasoning in the other way?
Let me show you how we can reason differently.
And the 4th behavior is I'm still indifferent on the filters but I apply a selection.
So these four behaviors, it needs to be explicitly clear and if you're speaking now that I'm explaining
them, it's not a good way to do the final test.
But again, I'm not a priest so that's up to you.
15 minutes break we meet again at 10 minutes to 6.
clovanote.naver.com