Many-To-Many in DAX Alberto Ferrari Senior Consultant SQLBI DBI413
Alberto Ferrari
Classical M2M We will start looking at the final result Then, we dive into the DAX code Demo – Classical M2M
Filter on Dim_CustomerFilter on Dim_Account
This filter is applied by the Tabular data model
FILTER: For each row in Dim_Account CALCULATE: filters the bridge
This filter is applied by the Tabular data model FILTER: For each row in Dim_Account CALCULATE: filters the bridge Only rows in Dim_Account where COUNTROWS () > 0 survive the FILTER
This filter is applied by the Tabular data model FILTER: For each row in Dim_Account CALCULATE: filters the bridge Only rows in Dim_Account where COUNTROWS () > 0 survive the FILTER SUM is evaluated only for the accounts filtered from the customers
AmountM2M_Correct := CALCULATE ( SUM (Fact_Transaction[Amount]), FILTER ( Dim_Account, CALCULATE ( COUNTROWS (Bridge_AccountCustomer) ) > 0 ) )
All the rows in the Account table survived the FILTER
Two rows in the Account table survived the FILTER
AmountM2M_Correct := CALCULATE ( SUM (Fact_Transaction[Amount]), FILTER ( Dim_Account, CALCULATE ( COUNTROWS (Bridge_AccountCustomer) ) > 0 ) )
The context is moved in a single Vertipaq operation
Cascading M2M Many-to-many with more than one bridge table Cascading many-to-many
Filter on Dim_CategoryFilter on Dim_Account The pattern is the same, but this time we need to jump two steps to complete our task
CALCULATE( SUM( Fact_Transaction[Amount] ), CALCULATETABLE ( SUMMARIZE ( BridgeAccountCustomer, DimAccount[ID_Account] ), SUMMARIZE ( Bridge_CustomerCategory, DimCustomer[ID_Customer] ) ) )
Need for some ETL here The bridge now «feels» three different filters, but the formula becomes a classical many to many and runs faster
Survey A first example of the usage of the many-to-many pattern Using M2M on Surveys
Question1 = «Job» Answer1 = «Consultant» Question2 = «Yearly Income»
Additional conditions to set the relationships with two tables in DAX only
Basket Analysis A pretty complex scenario, solved with the many-to-many pattern Basket Analysis Demo
This is the fact table… Do you really like to self-join it?
We can filter «Mountain Tire Tube» with this table but… where do we filter «Mountain Bike»?
2° filter: «Mountain Bike» 1° filter: «Mountain Tire Tube»
1° filter: «Mountain Bike» 2° filter: «Mountain Tire Tube» HavingProduct = Bought Both NotHavingProduct = Bought Bike, No Tire
Inactive Relationships
1° M2M Pattern 2° M2M Pattern
Querying M2M Well… what about performance of m2m in Tabular? Let us see them! M2M Performance
2,700, , ,440 9,000 4,000,000,000
DBI305 Developing and Managing a BI Semantic Model in Analysis Services DBI413 Many-to-Many Relationships in BISM Tabular DBI319 BISM: Multidimensional vs. Tabular DBI62-HOL Optimizing a MS SQL Server 2012 Tabular BI Semantic Model Book Signing at Book Store on Wednesday, June 13 th, 12:30pm-1:00pm
mva Microsoft Virtual Academy SQL Server 2012 Eval Copy Get Certified! Hands-On Labs
Connect. Share. Discuss. Learning Microsoft Certification & Training Resources TechNet Resources for IT Professionals Resources for Developers
Required Slide Complete an evaluation on CommNet and enter to win!
Scan the Tag to evaluate this session now on myTechEd Mobile Required Slide *delete this box when your slide is finalized Your MS Tag will be inserted here during the final scrub.