You are on page 1of 35

Julie Koesmarno | Consultant, MsSQLGirl

Patrick LeBlanc | Senior Technical Specialist, Microsoft


03 | Enriching a data model

Julie Koesmarno | Consultant, MsSQLGirl


Patrick LeBlanc | Senior Technical Specialist, Microsoft
Module Overview

Developing Analytical Calculations


Introduction to DAX Patterns
Building Data Model For Interactivity
Developing Analytical Calculations
Calculated Column

Can contain DAX formula


Calculated for each row immediately
Stored in the database
Recalculated when data is re-processed
Calculated Measure

Dynamic formula
Results depend on the context
Standard Aggregation ~ Autosum feature, e.g. COUNT or SUM
Custom Formula, results based on context will not show in SSDT
DEMO
Calculated Columns and Calculated Measures
Context in DAX Formula

Context enables dynamic analysis:


Formulas can change to reflect the current row / cell and any unrelated
data
Relationships and Filters can be used or ignored
3 types of context
Row
Query
Filter
Row Context

Ability to access all column values in the same table for the
current row
Ability to access all column values of related tables for the
current row

Multiple Rows
Some DAX functions can iterate value over a table
Inner and Outer Loop; Current Row values from the Inner Loop
is stored in memory
Row Context Example

=
[Freight] + RELATED ( 'Region'[TaxRate] )

---------------------------------------------------------
=
MAXX (
FILTER ( Sales, [ProdKey] = EARLIER ( [ProdKey] ) ),
Sales[OrderQty]
)
Query Context

Subset of data implicitly retrieved for a formula


Based on slicers or report filters; make use of defined
relationships
Query Context Example

=
SUM ( 'Sales'[Profit] )
Filter Context

Explicitly apply filter constraint to formula


Applies on top of other contexts, such as row context and query
context.
Useful for
Create filter constraints within formula
Ignoring current query filter
Selectively clearing and applying filter within formulas
Filter Functions

RELATED
FILTER
ALL
ALLEXCEPT
EARLIER, EARLIEST
And many more:
http://msdn.microsoft.com/en-us/library/ee634807.aspx
Filter Context

Revenue CYTD :=
CALCULATE (
[Revenue],
FILTER (
ALL ( 'Date' ),
'Date'[Calendar Year] = MAX ( 'Date'[Calendar Year] )
&& 'Date'[Date] <= MAX ( 'Date'[Date] )
)
)
Introduction to DAX Patterns

Many-to-many Scenario and Self-Join Hierarchy


Many To Many Classic

Scenario:
Bank Transactions of accounts that may have more than one or
more account holders.
Many To Many - Classic
DEMO
DAX Pattern: Many to Many Classic
Option 1

NumOfCustomers:=COUNTROWS(Bridge_AccountCustomer)
AmountM2M:=
CALCULATE(SUM([Amount]),
FILTER(Bridge_AccountCustomer,
Bridge_AccountCustomer[NumOfCustomers]
>= 1))
Option 2

AmountM2M_CrossTable :=
CALCULATE(SUM([Amount]),
Bridge_AccountCustomer,
Dim_Account,
Dim_Customer)
Option 3

AmountM2M_SumX :=
SUMX(
FILTER(Fact_Transaction,
COUNTROWS(Bridge_AccountCustomer) > 0),
Fact_Transaction[Amount])
Resources

The Many-to-Many Revolution 2.0


http://www.sqlbi.com/articles/many2many
Self Join Hierarchy
DEMO
DAX Pattern: Self Join Hierarchy
Steps - Create The Hierarchy
1. Create the employee hierarchy using Path materialise the levels
2. Calculate the current employee level
EmployeeHierarchyPath =
PATH([EmployeeKey],[ParentEmployeeKey])
3. Materialise all the levels
Level 3 =
LOOKUPVALUE([Full Name], [EmployeeKey],
PATHITEM([EmployeeHierarchyPath],3))
Other useful function -
Employee Level =
PATHLENGTH([EmployeeHierarchyPath])
Building Data Model For Interactivity

Defining Hierarchy, Metadata, KPI and Actions


DEMO
Enriching Data Model for Interactivity
via Hierarchy, Metadata, KPI and Actions
Define Hierarchy

Create and manage Hierarchy in Diagram View within SSDT


Set the Metadata

For Power View Table Properties:


Row Identifier
Keep Unique Rows
Default Image
Default Label
Column Description
KPI

Value
Goal
Status

Best adjusted (for seasonality) instead of against a static goal.


e.g Growth Rate current Quarter vs same Quarter last year
Creating Actions

In Pivot Table, Actions will be added to Additional Actions


Action Types

Top 4 Action Types:


Create Drillthrough
Launch URL
Launch SSRS
DAX Query Rowset
Create custom DAX
Create custom MDX
Enriching Tabular Model

Session Takeaways
Show analytical requirements can be met by enriching Tabular
Model with
Calculated Columns
Measures
DAX Patterns
Show user experience can be enriched by:
Adding KPI
Setting Metadata
Configuring Actions
2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the
U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

You might also like