Power BI-Power Pivot- customer orders last time (2)

Previous primarily use computed column in Power Pivot to understand two things:

First: What is the context of the line will only be applied when the function;

Second: the use of lines of context filter filters data.

This time I try to use the measure to achieve the same operation. The word metric looks a bit too professional, very difficult to see at a glance their specific meaning.

Popular point that the measure is a there is a fixed formula for computing the name . The measure has the following features

First : measure out on the table, which means that the measure can be defined in any of the Power Pivot table, at the same time, when referring to a column in a formula measure, you must specify the table name is displayed;

Second: the measure is automatically enabled lines of context, and therefore do not need to force a call Calculate function, but another table line context table screened through an associated relationship, or the need to call this function;

Third: the measure will only be loaded when actually gets called, but computed column will be together with the table load and operation, take up memory space.

Measure drag Excel pivot table with numeric field region similar field configuration actually calculated field PivotTable is generated automatically by the Excel metric perspective metric table automatically created has the following limitations

1, this metric can only be used in the current pivot table.

2, only a current field is calculated for drag data area, you can not refer to other fields

3, can be calculated using a fixed equation, can not extend their own

 

The presentation, I would like to duplicate in another non-customer information table up calculation rather than operations based on order data table, so first I need to get a distinct customer name column

In Excel2016 with Power BI Desktop Power Pivot has the form of a difference, or a new table can not create a new column, so we need the help of Power Query distinct customers to generate this column, operation is as follows:

1, select the order data table, click on "Data / from the table", the order data into Power Query query, and open the Power Query Editor

2019-08-17_222934

2, customers select the column, then click "Convert / Conversion to the list" to get a list of customer information

3, when the ribbon at the top of the dynamically loads a list of tools, find and click the "remove duplicates", the following results

2019-08-17_222934

4. Click "Home / Off and uploaded to," in the pop-load dialog box, select the table, the existing table, to find a table on the right side order data in a cell, and check the "add this data to the data model".

2019-08-17_222934

5. Click "Power Pivot / Management", do not click the "Add to Data Model" button, as in the previous step we have to add it to the model

 

Next we create a metric, metric Excel, Power Pivot is established in the computing area.

Before the establishment of the measure, we need to first establish a relationship between the customer and order data tables table, relationship is very simple, we switched to a relational view, build relationships, as shown below

2019-08-17_222934

Then we switch back to data view

1, we arbitrarily choose any one of a cell of the table, for example, a first grid "Customer" table;

2, formula editing bar at the click function area, enter the formula

Last Date Customer Order: = CALCULATE (MAX ( 'orders' [Order Date]), ALLEXCEPT ( 'order data', 'Order Data' [customer]))

A couple of points:

First: the need to measure metric names that begin, but do not need a computed column

Second: Excel measure is defined using the: =, and Power BI Desktop is used directly =

Third: When a measure is referenced in the column, must all columns must specify the table name, column calculated, if the referenced column of the current table, you can omit the table name

2019-08-17_222934

The content can be seen from the above formula, the formulas and measure formula column is almost the same, except when the reference field is calculated listed in this table, other than the table name can be omitted.

 

Next we look at the similarities and differences in results when applied to different tables measure

1, first of all, we each add a computed column in the orders table and the Customer table, the same formula

= [Customers last Order Date]

2019-08-17_2229342019-08-17_222934

Result Analysis 1

Results found: The results of the customer table is wrong, order data calculations are correct; this is why it?

Analysis: Because ALLEXCEPT function, we reserve the context of the screening is to change the order of columns in the data table based on the customer rather than the customer the customer table, we will measure the equation of the form:

Last Date Customer Order: the CALCULATE = (MAX ( ' orders ' [Order Date]), ALLEXCEPT ( ' client ' , ' customer ' [customer]))

2019-08-17_222934

Analysis of the results:

Results found: In this case the customer correctly calculated results in the table, but the data in the table to calculate the order is wrong

summary:

When used in metric screening filters, ensure that the corresponding operation is consistent table (Table A in the operation, which should be screened column A column in the table)

Guess you like

Origin www.cnblogs.com/alexywt/p/11371713.html