Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Tabular Modeling Cookbook

You're reading from   Microsoft Tabular Modeling Cookbook No prior knowledgeof tabular modeling is needed to benefit from this brilliant cookbook. This is the total guide to developing and managing analytical models using the Business Intelligence Semantic Models technology.

Arrow left icon
Product type Paperback
Published in Dec 2013
Publisher Packt
ISBN-13 9781782170884
Length 320 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Paul te Braak Paul te Braak
Author Profile Icon Paul te Braak
Paul te Braak
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Excel FREE CHAPTER 2. Importing Data 3. Advanced Browsing Features 4. Time Calculations and Date Functions 5. Applied Modeling 6. Programmatic Access via Excel 7. Enterprise Design and Features 8. Enterprise Management 9. Querying the Tabular Model with DAX 10. Visualizing Data with Power View A. Installing PowerPivot and Sample Databases Index

Creating model calculations

The sales model that has been developed in this chapter allows the user to interrogate data from the order list by products, customers, and dates. In doing so, the user can create an implicit measure so that the underlying data is aggregated according to the current filter context. The aggregation function of implicit measures is determined by the underlying data type of the column that is used for the measure. This method offers the user the ability to create and show simple calculations from the model data. However, it does not create a robust model because the calculations aren't readily selectable by the user and the calculation definition is not conformed within the model.

This recipe introduces calculations which are contained within the model and presented to the user as measures. DAX (the tabular model language introduced in Adding fields to tables recipe) is used to define measures, so that it can explicitly use these measures in the model. Furthermore, the ability to create measures through a complex DAX allows the model designer a larger degree of flexibility than is involved with implicit measures.

Getting ready

This recipe assumes that the sales model created in Linking fields between tables recipe is available and that the appropriate relationships exist among the Product, Subcategory, and Category tables.

By default, a table in Data View will have a horizontal line that does not show any data. This is referred to as the calculation area. If this is not visible, ensure that the Calculation Area button is selected in the Home menu.

Getting ready

How to do it…

There are many ways to create simple measures. Let's start with the automatic creation of measures.

  1. Select any cell in the order_quantity field. Then, from the ribbon, select the SUM function from the AutoSum drop-down. A new calculation will be created in the calculation area as:
    Sum of order_quantity:=SUM([order_quantity])
  2. In the formula bar, select the name of the measure (Sum of order_quantity) and rename it to Total Order Quantity. The calculation should now look like this:
    Total Order Quantity:=SUM([order_quantity])
    How to do it…
  3. Right-click on the calculation, select Format Cells... from the pop-up menu, and specify the format as a number format—(decimal number) with zero decimal places and click on the User 1000 separator (,) checkbox.
  4. Select this group of columns: unit_cost, tax, total_price, and total_profit, by selecting the unit_cost column and dragging the mouse across to the total_profit column.
  5. Click on the AutoSum button to create your calculations for these columns.
  6. Rename the measures to Total Cost, Total Tax, Total Price, and Total Profit respectively with the same format as Total Order Quantity. Note that the format of the number is inherited as currency.
  7. Select the cell in the calculation area under the unit_price column and type the formula:
    Average Price:=AVERAGE([unit_price])

    Intellisence provides a list of formulas available (based on the expression that is entered) and a description of the function, as shown in the following screenshot:

    How to do it…
  8. Hide the following fields of the Sales table: order_quantity, unit_price, tax, total_price, and total_profit.
  9. Return to the PowerPivot Field List pane (in Excel) and refresh the model. Existing implicit calculations that were based on existing fields are removed from the model and the Sales table now includes the additional measures which were created. These measures can now be placed in the pivot tables (value) field list.

    Tip

    Explicit measure cannot be used in a slicer, filter, or as row or column labels.

    How to do it…

How it works…

Measures that are created in the calculation area operate in the same manner as implicit measures. That is, the aggregation function is applied to the filtered data specified by the row and filter context within the client tool.

Because the measures are explicitly defined in the model they are called explicit measures and interpreted by the client tool as measures (many client tools detect an explicit measure as a special type of field and treat it differently than a table's standard field or dimension field).

There's more...

By default, the tabular model created in PowerPivot will display the model through a PowerPivot pivot table. This shows the model in its tabular form where measures and columns are shown with respect to the tables that they relate to. For example, the measures created in the Creating model calculations recipe appear under the Sales table node. In order to compare this (tabular) view with that of a traditional OLAP client, simply do the following:

  1. Ensure that a cell within the pivot table is selected.
  2. Activate PivotTable Field List by clicking on the Field List button from the Options tab of the PivotTable Tools menu.
    There's more...
  3. The PivotTable Field List window opens, which shows the tabular model in the multidimensional (client) format.
    There's more...

The client tool (PivotTable Field List) shows the model in a different format and represents how a client tool interpretation of the model would be shown. Here, the measures are shown in measure groups and are not included as table objects.

You have been reading a chapter from
Microsoft Tabular Modeling Cookbook
Published in: Dec 2013
Publisher: Packt
ISBN-13: 9781782170884
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image