SlideShare a Scribd company logo
1 of 48
Download to read offline
#SQLSAT777
What is in reality a DAX filter
context
Marco Pozzan
#SQLSAT777
Organizers
GetLatestVersion.it
#SQLSAT777
Sponsors
#SQLSAT777
Who am I? (Marco Pozzan)
Business intelligence consultant at www.methode.it
Teaching at the University of Pordenone in the course of data analysis and Big Data
Community Lead of 1nn0va (www.innovazionefvg.net)
MCP, MCSA, MCSE, MCT and since 2014 MVP and since 2016 MVP Reconnect for
Microsoft Data Platform and speaker in several conferences on the topic
marco.pozzan@methode.it
@marcopozzan.it
www.marcopozzan.it
http://www.scoop.it/u/marco-pozzan
http://paper.li/marcopozzan/1422524394
#SQLSAT777
Let’s start
#SQLSAT777
Agenda
Recap filter context
Base Tables vs Expanded tables
Filter context in deep
• Filter context propagation
• Filter context operators
Arbitrary shaped set
Understanding what ALLSELECTED does
#SQLSAT777
Recap filter context
• Defined by the context introduced by a pivot
table or visual
• Rows outside of the filter context are not
considered for the computation
• Can be created with specific functions too
#SQLSAT777
Base table
vs
Expanded table
#SQLSAT777
Base table and Expanded table
• A base table is a standard
table in the model
• Product and Subcategory
are base tables
• The relationship between
two tables is LEFT OUTER
JOIN
#SQLSAT777
Base table vs Expanded table
• An expanded table of
product is a table that have
all subcategory column
beside the product column
• Following the left outer join
relationship
• For each base table there
is an expanded version
#SQLSAT777
Base table vs Expanded table
Each Table = all of its columns (native columns)
+
all of the columns in all related tables
(related columns)
This theory does not happen physically inside the
engine but help us understanding how filters
context work
#SQLSAT777
The RELATED function
Do you remember the RELATED function?
is able to follow a chain of relationship and retrive
the value of a column in a RELATED table. It’s right?
(not true ☺)
• Doesn’t follow relationships but it
simply grants you access to the
related columns (expanded table)
#SQLSAT777
What happens with single relation?
• Sales exapanded table contains
the ALL column of the ALL model ☺
• Product expanded table contains
all Product columns + all
Subcategory columns
• Calendar and SubCategory
expanded table are equal to base
table
#SQLSAT777
What happens with bidirectional?
• Sales exapanded table contains ALL the
columns of the ALL model ☺
• Product expanded table contains all
product product + all column subcategory
• SubCategory expanded table is equal to
base table
• !!!Calendar has not the expanded table
but through the injection of filtering code in
the DAX calendar is able to filter Sales. And
Sales is able to filter Calendar
#SQLSAT777
Filter context
in deep
#SQLSAT777
Filter context propagation: Rule 1
• The filter set on Product[Name] = “classic Vest, S”(native
column)
• I will filter Sales because Sales contains product[name] as an
expanded column (Sales Expanded)
So filtering an individual column means filtering all the tables
that contain that column either as native column or as a releted
column.
#SQLSAT777
Filter context propagation: Rule 2
The filter context propagates only from 1 side
to Many side. It’s right?
(not really true ☺)
• Means placing a filter on all column of the product table
• Product table is being filtered as a whole and filtering the
product table. But I am really filtering the expanded table of
product (all column that belong to a SubCategory) and i
am really filtering SubCategory
I am moving the filter from the many to the one side!!! ☺
#SQLSAT777
Filter context propagation: Rule 3
When filtering by using the Product table, the
Subcategory table is really filtered. Does the same
happens when you filter by one column of Product ?
If i filter an individual column of product then I’m
not filtering subcategory,there is a big different
between filtering a table and filtering a
column(work on the base table)
#SQLSAT777
Recap: filter context propagation
Column filter
• Work on the base table
• Does not refer to related column
Table Filter
• Work on the expanded table
• Always includes related columns
Table interactions
• When the same column (native o related) is
referred by different contexts last filter
wins (example nested calculate)
• Ex. “Classic Vest, S” wins
#SQLSAT777
Year MonthName
2013 December
2014 January
Filter context and operators
• A filter context is based on tuple
• Tuple is a given value for one set of columns
• A filter is a set of tuple
• A filter context is a set of filters
Year MonthName
2013 December
2014 January
Tupla
Year MonthName
2013 December
2014 January
Name
Classic Vest, S
AWC Logo Cap
Tupla
Name
Classic Vest, S
AWC Logo Cap
#SQLSAT777
Filter context and operators
• A filter context is a set of filters
Year MonthName
2013 April
2012 May
Name
Classic Vest, S
AWC Logo Cap
Filter 1
Filter 2
#SQLSAT777
Filter context and operators
There are three basic operators that DAX uses to mix different filter
context
• Intersect
• Allow to performs intersection
• Overwrite
• Allow to overwrite a filter with a new filter
• Remove
• Remove a filter from a existing filter
#SQLSAT777
Name
Classic Vest, S
Filter context and operators: Intersect
You have 2 filter context, and
you want to intersect them in
a new filter context (that is to
put them in what we called a
logical AND)
Intersect is the operator that
CALCULATE uses when it needs
to merge together filters that
you create as a separate filter
parameter in the statement.
Year
2013
Name
Classic Vest, S
Year
2013
#SQLSAT777
Filter context and operators: Overwrite
is used by CALCULATE not when it
needs to merge different filters in
the same column, but when you have
nested CALCULATE.
1. Remove any reference for Name from
external filter (AWC Logo cap)
2. Intersect with the new filter context from
internal filter)
if it tries to use intersect it would
create an empty set
Name
AWC Logo Cap
Name
Classic Vest, S
Name
Classic Vest, S
“Classic Vest, S”
overwrites “AWC
Logo Cap”
Name 11
2
#SQLSAT777
Filter context and operators: Remove
ALL return all the column values when used
as a top level function in CALCULATE. It’s
right?
(Not true )
In a CALCULATE filter ALL doesn’t use ALL but applies REMOVE
• Remove the filters from all the columns contained in the table it returns
• REMOVE operator is the operator used by ALL when it used as a top-level
function inside CALCULATE
#SQLSAT777
The new way: using ALL product[Name]
doesn’t mean returning all the Product
it means remove the filter from the product
Filter context and operators:Remove example
Old way of thinking about ALL in
CALCULATE
Name
chain
blade
steam
...
Name
chain
blade
steam
…..
Name
AWC Logo
Cap
Name
AWC Logo Cap
Empty
Filter
Result
Result
Name
#SQLSAT777
Why the operator is important
The equivalent DAX formula
The result is the same.
It’s right?
606 (All Products)
158 (All
Products
sold)
#SQLSAT777
Recap Operator
A and B are two tables
• INTERSECT (A intersect B)
• Puts the filter in AND
• OVERWRITE (A overwrite B)
• Replace filter in B
• This operator not exist in reality but use REMOVE + INTERSECT
• REMOVE
• Remove columns from the filter context
• Used by ALL in a CALCULATE when it used as a top-level function
#SQLSAT777
Arbitrary
shaped set
#SQLSAT777
Simple Filter
Imagine that you have this filter context
This filter is simplified as the intersection of single-column filter
if any filter can be simplified as the intersection of the individual column
filters then we call it a simple filter (filter equivalency)
Year MonthName
2013 April
2012 May
Year
2013
2012
MonthName
April
May
#SQLSAT777
Arbitrarily shaped set by UI
• simple filters are good because they don’t create any problem at all
• there are also filters that cannot be simplified
this filter cannot be simplified. You cannot express this filter as
the intersection of the individual column filters.
Year MonthName
2013 April
2012 May
Year
2013
2012
MonthName
April
May
This arbitrarily shaped cannot be created as one
filter on the year and another one on the month!!!
#SQLSAT777
Problem with Arbitrarily shaped set
Measure than compute the average of sales at the month granularity
Why is the Total wrong? In the next slide you will see what happens
is the interaction between
arbitrarily shaped sets
and context transition and
the operators in calculate
#SQLSAT777
Problem with Arbitrarily shaped set
1. In Total there is an iteration. For each
month we compute the monthly sales.
2. During 1 iteration the selected month is April and the original filter
context contain 2013 April, 2012 May.
Calculate through context
transition will use overwrite
that remove MonthName by
Original Filter context
3. Each iteration is not computing the sales
of a single month but the sales of 2 year
together, and the average was much higher:
OVERWRITE destroy arbitrarily shape set
Year MonthName
2013 April
2012 May
MonthName
April
MonthName
April
Year
2013
2012
#SQLSAT777
Year MonthName
2013 April
2012 May
Year MonthName
2013 April
2012 May
Solution with Arbitrarily shaped set
KEEPFILTER modify the behaviour of CALCULATE when the context
transition happening during iterations
if there is a context transition and invoke CALCULATE, don’t use
OVERWRITE, instead use INTERSECT (used as a top level function)
KEEPFILTER
preserve
arbitrarily shape set!!!
MonthName
April
MonthName
April
#SQLSAT777
Be careful to the SUMMARIZE
• Is the only function in DAX that create at the same time a row context
and filter context and both are working togheter
• The reason why sometime SUMMARIZE
returns strange values it’s:
• the row context created by SUMMARIZE will be subject to context transaction
whenever you call a measure from inside your code
• And context transition use remove and is able to destroy arbitrarily
sets (model,color)
Row context on
Test[Color]
Filter context on
Test[Color]
Model Color
Bike Blue
Model Color
Bike Green
shirt Green
Model Color
Bike Red
shirt Red
Model Color
Bike
Model Color
Bike
shirt
Model Color
Bike
shirt
#SQLSAT777
Recap: Arbitrarily shaped set
• not use SUMMARIZE to compute anything!!!
• Use it to do a grouping by
• But whenever you want to compute some values use ADDCOLUMNS
instead.
• ADDCOLUMNS is not subject to this behavior ☺
• KEEPFILTER preserve arbitrary shaped set
#SQLSAT777
Understanding
what
ALLSELECTED does
#SQLSAT777
Understanding what ALLSELECTED does
ALLSELECTED Obtain visual totals (that is the total that the user is
looking at) in queries.
• Removes filters context from columns and rows in the current query,
• Retaining all other filters context
• Retaining explicit filters context (when use CALCULATE)
It’s true if and only if no
iteration is happening!!!!
#SQLSAT777
Understanding shadow filter context
• Special filter context created by iterators which is always inactive
except for certain situations
• The DAX above generates a shadow filter context that contains
the values of Product[Color] in the current filter context or
explicit filter context when iterator starts. (It is inactive)
• The shadow filter context is activated by ALLSELECTED!!!
#SQLSAT777
ALLSELECTED(Column) is a table function
• no shadow context to activate (no previous shadow context) because ALLSELECTED is
contained in CONCATENATEX that creates a shadow contex
• ALLSELECTED works on filter context but when a column is used as parameter it ignores
the cross filters. The result is that Product[Product] contains all values.
Brand Color Product
Contoso Red Bike
Contoso Green Helmet
Contoso Blue Shoes
Tailspin Toys Red Robot
Tailspin Toys Green Shirt
Tailspin Toys Blue Rollerblades
Fabrikam Red Motorbike
Fabrikam Green Keyboard
Fabrikam Blue Piano
#SQLSAT777
ALLSELECTED(Column) is a table function
• ADDCOLUMNS creates a shadow context (shadow context 1), which is the result of VALUES()
in the defined filter context when iterator starts ("Contoso","Fabrikam" )
• CONCATENATEX creates another shadow context (shadow context 2) and ALLSELECTED
activates and uses the last shadow context, which is shadow context 1
Brand
Contoso
Fabrikam
Brand Color
Contoso Red
Contoso Green
Contoso Blue
Tailspin Toys Red
Tailspin Toys Green
Tailspin Toys Blue
Fabrikam Red
Fabrikam Green
Fabrikam Blue
#SQLSAT777
ALLSELECTED(Table) is a table function
• No shadow context to activate (no previous shadow context), ALLSELECTED is contained
in CONCATENATEX which creates a shadow context (that remains unactive)
• When a table is the parameter the cross filters are considered as opposed to when a
column is used as a parameter
Brand Color Product
Contoso Red Bike
Contoso Green Helmet
Contoso Blue Shoes
Tailspin Toys Red Robot
Tailspin Toys Green Shirt
Tailspin Toys Blue Rollerblades
Fabrikam Red Motorbike
Fabrikam Green Keyboard
Fabrikam Blue Piano
#SQLSAT777
ALLSELECTED(Table) is a table function
• ADDCOLUMNS creates a shadow context with ALL(Product[Color]) (shadow Context 1)
• CONCATENATEX creates another shadow context (shadow context 2) and ALLSELECTED
activates and uses the last shadow context, which is shadow context 1 for [Color], plus
the original filter on Brands
Brand Color Product
Contoso Red Bike
Contoso Green Helmet
Contoso Blue Shoes
Tailspin Toys Red Robot
Tailspin Toys Green Shirt
Tailspin Toys Blue Rollerblades
Fabrikam Red Motorbike
Fabrikam Green Keyboard
Fabrikam Blue Piano
#SQLSAT777
Brand Color Product Quantity
Contoso Red Bike 10
Contoso Green Helmet 20
Contoso Blue Shoes 30
Tailspin
Toys
Red Robot 40
Tailspin
Toys
Green Shirt 50
Tailspin
Toys
Blue
Rollerbla
des
60
Fabrikam Red
Motorbi
ke
70
Fabrikam Green
Keyboar
d
80
Fabrikam Blue Piano 90
ALLSELECTED() is a CALCULATE modifier
• No shadow context to activate (no previous shadow context), ALLSELECTED
performs ALLSELECTED on all columns, the filter context is used.
#SQLSAT777
ALLSELECTED() is a CALCULATE modifier
• Using ALLSELECTED as a CALCULATE filter argument means transforming a shadow
filter context into an explicit filter context
• ALLSELECTED activates and uses a shadow filter context that contains ALL [Brand]
and this is the new explicit filter context, SUM is computed on all brand (60 +
150 + 210 = 450) and then this computation is repeated by SUMX 3 times (one
for each brand)
Brand Color Product Quantity
Contoso Red Bike 10
Contoso Green Helmet 20
Contoso Blue Shoes 30
Tailspin Toys Red Robot 40
Tailspin Toys Green Shirt 50
Tailspin Toys Blue Rollerblades 60
Fabrikam Red Motorbike 70
Fabrikam Green Keyboard 80
Fabrikam Blue Piano 90
#SQLSAT777
Recap ALLSELECTED
ALLSELECTED(<Table>)
• Applies the last available
shadow filter context,
on any column that has
one
• In absence of shadow
context the defined
(normal) filter context is
used
• Cross filters are
considered
ALLSELECTED(<Column>)
• Applies the last available
shadow filter context
on the given column
• In absence of shadow
context to apply, all the
column values are
returned
• Cross filters are not
considered
ALLSELECTED()
• Behaves as if all the
columns are used as
parameter
• Applies the last available
shadow filter context on
all the columns
• In absence of shadow
context to apply, all the
column values are
returned
• Cross filters are not
considered
#SQLSAT777
References
• https://www.sqlbi.com/articles/the-definitive-guide-to-allselected/
• https://www.sqlbi.com/blog/marco/2015/08/05/the-allselected-
function-under-the-cover-dax-tabular-powerpivot-powerbi/
• https://www.sqlbi.com/articles/understanding-allselected/
#SQLSAT777
Thanks!

More Related Content

What's hot

SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition StrategyHamid J. Fard
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBOvais Tariq
 
Hp vertica certification guide
Hp vertica certification guideHp vertica certification guide
Hp vertica certification guideneinamat
 
2. Introduction-to-MSSQL-Server.pptx
2. Introduction-to-MSSQL-Server.pptx2. Introduction-to-MSSQL-Server.pptx
2. Introduction-to-MSSQL-Server.pptxAyobamiAdelekeMDM
 
Oracle sql analytic functions
Oracle sql analytic functionsOracle sql analytic functions
Oracle sql analytic functionsmamamowebby
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)Ehtisham Ali
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptxAnkit Rai
 
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDBHistogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDBMydbops
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized tableAmrit Kaur
 
İleri Seviye T-SQL Programlama - Chapter 10
İleri Seviye T-SQL Programlama - Chapter 10İleri Seviye T-SQL Programlama - Chapter 10
İleri Seviye T-SQL Programlama - Chapter 10Cihan Özhan
 
Researching for Sources & Gathering Supporting Material for a Public Speech
Researching for Sources & Gathering Supporting Material for a Public SpeechResearching for Sources & Gathering Supporting Material for a Public Speech
Researching for Sources & Gathering Supporting Material for a Public SpeechWafi Badji
 
More mastering the art of indexing
More mastering the art of indexingMore mastering the art of indexing
More mastering the art of indexingYoshinori Matsunobu
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresqlbotsplash.com
 

What's hot (14)

SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition Strategy
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
Hp vertica certification guide
Hp vertica certification guideHp vertica certification guide
Hp vertica certification guide
 
2. Introduction-to-MSSQL-Server.pptx
2. Introduction-to-MSSQL-Server.pptx2. Introduction-to-MSSQL-Server.pptx
2. Introduction-to-MSSQL-Server.pptx
 
Oracle sql analytic functions
Oracle sql analytic functionsOracle sql analytic functions
Oracle sql analytic functions
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDBHistogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
 
İleri Seviye T-SQL Programlama - Chapter 10
İleri Seviye T-SQL Programlama - Chapter 10İleri Seviye T-SQL Programlama - Chapter 10
İleri Seviye T-SQL Programlama - Chapter 10
 
Researching for Sources & Gathering Supporting Material for a Public Speech
Researching for Sources & Gathering Supporting Material for a Public SpeechResearching for Sources & Gathering Supporting Material for a Public Speech
Researching for Sources & Gathering Supporting Material for a Public Speech
 
Azure SQL Data Warehouse
Azure SQL Data Warehouse Azure SQL Data Warehouse
Azure SQL Data Warehouse
 
More mastering the art of indexing
More mastering the art of indexingMore mastering the art of indexing
More mastering the art of indexing
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
 

Similar to What is in reality a DAX filter context

Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Amanda Lam
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developerAhsan Kabir
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008wharrislv
 
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansSqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansMarek Maśko
 
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...Anna Loughnan Colquhoun
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's Newdpcobb
 
Microsoft Excel introduction
Microsoft Excel introductionMicrosoft Excel introduction
Microsoft Excel introductionJesus Obenita Jr.
 
Technical stream presentation
Technical stream presentationTechnical stream presentation
Technical stream presentationDynistics
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?loginworks software
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices documentAshwani Pandey
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"Lviv Startup Club
 

Similar to What is in reality a DAX filter context (20)

Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Set Analyse OK.pdf
Set Analyse OK.pdfSet Analyse OK.pdf
Set Analyse OK.pdf
 
Dax en
Dax enDax en
Dax en
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns
 
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansSqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
 
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
 
Microsoft Excel introduction
Microsoft Excel introductionMicrosoft Excel introduction
Microsoft Excel introduction
 
Technical stream presentation
Technical stream presentationTechnical stream presentation
Technical stream presentation
 
Indexes overview
Indexes overviewIndexes overview
Indexes overview
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices document
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Module07
Module07Module07
Module07
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"
 

More from Marco Pozzan

Metadata Driven Pipeline with Microsoft Fabric
Metadata Driven Pipeline  with Microsoft FabricMetadata Driven Pipeline  with Microsoft Fabric
Metadata Driven Pipeline with Microsoft FabricMarco Pozzan
 
Data Warehouse with Fabric on data lakehouse
Data Warehouse with Fabric on data lakehouseData Warehouse with Fabric on data lakehouse
Data Warehouse with Fabric on data lakehouseMarco Pozzan
 
Data modelling for Power BI
Data modelling for Power BIData modelling for Power BI
Data modelling for Power BIMarco Pozzan
 
SlideModellingDataSat.pdf
SlideModellingDataSat.pdfSlideModellingDataSat.pdf
SlideModellingDataSat.pdfMarco Pozzan
 
Quanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseQuanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseMarco Pozzan
 
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-service
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-servicePower BI: Introduzione ai dataflow e alla preparazione dei dati self-service
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-serviceMarco Pozzan
 
Microsoft Power BI fast with aggregation and composite model
Microsoft Power BI fast with aggregation and composite modelMicrosoft Power BI fast with aggregation and composite model
Microsoft Power BI fast with aggregation and composite modelMarco Pozzan
 
REAL TIME ANALYTICS INFRASTRUCTURE WITH AZURE
REAL TIME ANALYTICS INFRASTRUCTURE WITH AZUREREAL TIME ANALYTICS INFRASTRUCTURE WITH AZURE
REAL TIME ANALYTICS INFRASTRUCTURE WITH AZUREMarco Pozzan
 
Big data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power biBig data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power biMarco Pozzan
 
Azure saturday pn 2018
Azure saturday pn 2018Azure saturday pn 2018
Azure saturday pn 2018Marco Pozzan
 
Power B: Cleaning data
Power B: Cleaning dataPower B: Cleaning data
Power B: Cleaning dataMarco Pozzan
 
Power bi Clean and Modelling (SQL Saturday #675)
Power bi Clean and Modelling  (SQL Saturday #675)Power bi Clean and Modelling  (SQL Saturday #675)
Power bi Clean and Modelling (SQL Saturday #675)Marco Pozzan
 
Power BI and business application platform
Power BI and business application platformPower BI and business application platform
Power BI and business application platformMarco Pozzan
 

More from Marco Pozzan (20)

Metadata Driven Pipeline with Microsoft Fabric
Metadata Driven Pipeline  with Microsoft FabricMetadata Driven Pipeline  with Microsoft Fabric
Metadata Driven Pipeline with Microsoft Fabric
 
Data Warehouse with Fabric on data lakehouse
Data Warehouse with Fabric on data lakehouseData Warehouse with Fabric on data lakehouse
Data Warehouse with Fabric on data lakehouse
 
Data modelling for Power BI
Data modelling for Power BIData modelling for Power BI
Data modelling for Power BI
 
SlideModellingDataSat.pdf
SlideModellingDataSat.pdfSlideModellingDataSat.pdf
SlideModellingDataSat.pdf
 
Datamart.pdf
Datamart.pdfDatamart.pdf
Datamart.pdf
 
Datamart.pptx
Datamart.pptxDatamart.pptx
Datamart.pptx
 
Quanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseQuanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless Synapse
 
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-service
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-servicePower BI: Introduzione ai dataflow e alla preparazione dei dati self-service
Power BI: Introduzione ai dataflow e alla preparazione dei dati self-service
 
Data flow
Data flowData flow
Data flow
 
Microsoft Power BI fast with aggregation and composite model
Microsoft Power BI fast with aggregation and composite modelMicrosoft Power BI fast with aggregation and composite model
Microsoft Power BI fast with aggregation and composite model
 
REAL TIME ANALYTICS INFRASTRUCTURE WITH AZURE
REAL TIME ANALYTICS INFRASTRUCTURE WITH AZUREREAL TIME ANALYTICS INFRASTRUCTURE WITH AZURE
REAL TIME ANALYTICS INFRASTRUCTURE WITH AZURE
 
Big data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power biBig data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power bi
 
Azure saturday pn 2018
Azure saturday pn 2018Azure saturday pn 2018
Azure saturday pn 2018
 
Power B: Cleaning data
Power B: Cleaning dataPower B: Cleaning data
Power B: Cleaning data
 
Power bi Clean and Modelling (SQL Saturday #675)
Power bi Clean and Modelling  (SQL Saturday #675)Power bi Clean and Modelling  (SQL Saturday #675)
Power bi Clean and Modelling (SQL Saturday #675)
 
Power BI and business application platform
Power BI and business application platformPower BI and business application platform
Power BI and business application platform
 
Optimizing dax
Optimizing daxOptimizing dax
Optimizing dax
 
Optimizing dax
Optimizing daxOptimizing dax
Optimizing dax
 
Power bi + Flow
Power bi + FlowPower bi + Flow
Power bi + Flow
 
Power BI
Power BIPower BI
Power BI
 

Recently uploaded

Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Pooja Nehwal
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 

Recently uploaded (20)

Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 

What is in reality a DAX filter context

  • 1. #SQLSAT777 What is in reality a DAX filter context Marco Pozzan
  • 4. #SQLSAT777 Who am I? (Marco Pozzan) Business intelligence consultant at www.methode.it Teaching at the University of Pordenone in the course of data analysis and Big Data Community Lead of 1nn0va (www.innovazionefvg.net) MCP, MCSA, MCSE, MCT and since 2014 MVP and since 2016 MVP Reconnect for Microsoft Data Platform and speaker in several conferences on the topic marco.pozzan@methode.it @marcopozzan.it www.marcopozzan.it http://www.scoop.it/u/marco-pozzan http://paper.li/marcopozzan/1422524394
  • 6. #SQLSAT777 Agenda Recap filter context Base Tables vs Expanded tables Filter context in deep • Filter context propagation • Filter context operators Arbitrary shaped set Understanding what ALLSELECTED does
  • 7. #SQLSAT777 Recap filter context • Defined by the context introduced by a pivot table or visual • Rows outside of the filter context are not considered for the computation • Can be created with specific functions too
  • 9. #SQLSAT777 Base table and Expanded table • A base table is a standard table in the model • Product and Subcategory are base tables • The relationship between two tables is LEFT OUTER JOIN
  • 10. #SQLSAT777 Base table vs Expanded table • An expanded table of product is a table that have all subcategory column beside the product column • Following the left outer join relationship • For each base table there is an expanded version
  • 11. #SQLSAT777 Base table vs Expanded table Each Table = all of its columns (native columns) + all of the columns in all related tables (related columns) This theory does not happen physically inside the engine but help us understanding how filters context work
  • 12. #SQLSAT777 The RELATED function Do you remember the RELATED function? is able to follow a chain of relationship and retrive the value of a column in a RELATED table. It’s right? (not true ☺) • Doesn’t follow relationships but it simply grants you access to the related columns (expanded table)
  • 13. #SQLSAT777 What happens with single relation? • Sales exapanded table contains the ALL column of the ALL model ☺ • Product expanded table contains all Product columns + all Subcategory columns • Calendar and SubCategory expanded table are equal to base table
  • 14. #SQLSAT777 What happens with bidirectional? • Sales exapanded table contains ALL the columns of the ALL model ☺ • Product expanded table contains all product product + all column subcategory • SubCategory expanded table is equal to base table • !!!Calendar has not the expanded table but through the injection of filtering code in the DAX calendar is able to filter Sales. And Sales is able to filter Calendar
  • 16. #SQLSAT777 Filter context propagation: Rule 1 • The filter set on Product[Name] = “classic Vest, S”(native column) • I will filter Sales because Sales contains product[name] as an expanded column (Sales Expanded) So filtering an individual column means filtering all the tables that contain that column either as native column or as a releted column.
  • 17. #SQLSAT777 Filter context propagation: Rule 2 The filter context propagates only from 1 side to Many side. It’s right? (not really true ☺) • Means placing a filter on all column of the product table • Product table is being filtered as a whole and filtering the product table. But I am really filtering the expanded table of product (all column that belong to a SubCategory) and i am really filtering SubCategory I am moving the filter from the many to the one side!!! ☺
  • 18. #SQLSAT777 Filter context propagation: Rule 3 When filtering by using the Product table, the Subcategory table is really filtered. Does the same happens when you filter by one column of Product ? If i filter an individual column of product then I’m not filtering subcategory,there is a big different between filtering a table and filtering a column(work on the base table)
  • 19. #SQLSAT777 Recap: filter context propagation Column filter • Work on the base table • Does not refer to related column Table Filter • Work on the expanded table • Always includes related columns Table interactions • When the same column (native o related) is referred by different contexts last filter wins (example nested calculate) • Ex. “Classic Vest, S” wins
  • 20. #SQLSAT777 Year MonthName 2013 December 2014 January Filter context and operators • A filter context is based on tuple • Tuple is a given value for one set of columns • A filter is a set of tuple • A filter context is a set of filters Year MonthName 2013 December 2014 January Tupla Year MonthName 2013 December 2014 January Name Classic Vest, S AWC Logo Cap Tupla Name Classic Vest, S AWC Logo Cap
  • 21. #SQLSAT777 Filter context and operators • A filter context is a set of filters Year MonthName 2013 April 2012 May Name Classic Vest, S AWC Logo Cap Filter 1 Filter 2
  • 22. #SQLSAT777 Filter context and operators There are three basic operators that DAX uses to mix different filter context • Intersect • Allow to performs intersection • Overwrite • Allow to overwrite a filter with a new filter • Remove • Remove a filter from a existing filter
  • 23. #SQLSAT777 Name Classic Vest, S Filter context and operators: Intersect You have 2 filter context, and you want to intersect them in a new filter context (that is to put them in what we called a logical AND) Intersect is the operator that CALCULATE uses when it needs to merge together filters that you create as a separate filter parameter in the statement. Year 2013 Name Classic Vest, S Year 2013
  • 24. #SQLSAT777 Filter context and operators: Overwrite is used by CALCULATE not when it needs to merge different filters in the same column, but when you have nested CALCULATE. 1. Remove any reference for Name from external filter (AWC Logo cap) 2. Intersect with the new filter context from internal filter) if it tries to use intersect it would create an empty set Name AWC Logo Cap Name Classic Vest, S Name Classic Vest, S “Classic Vest, S” overwrites “AWC Logo Cap” Name 11 2
  • 25. #SQLSAT777 Filter context and operators: Remove ALL return all the column values when used as a top level function in CALCULATE. It’s right? (Not true ) In a CALCULATE filter ALL doesn’t use ALL but applies REMOVE • Remove the filters from all the columns contained in the table it returns • REMOVE operator is the operator used by ALL when it used as a top-level function inside CALCULATE
  • 26. #SQLSAT777 The new way: using ALL product[Name] doesn’t mean returning all the Product it means remove the filter from the product Filter context and operators:Remove example Old way of thinking about ALL in CALCULATE Name chain blade steam ... Name chain blade steam ….. Name AWC Logo Cap Name AWC Logo Cap Empty Filter Result Result Name
  • 27. #SQLSAT777 Why the operator is important The equivalent DAX formula The result is the same. It’s right? 606 (All Products) 158 (All Products sold)
  • 28. #SQLSAT777 Recap Operator A and B are two tables • INTERSECT (A intersect B) • Puts the filter in AND • OVERWRITE (A overwrite B) • Replace filter in B • This operator not exist in reality but use REMOVE + INTERSECT • REMOVE • Remove columns from the filter context • Used by ALL in a CALCULATE when it used as a top-level function
  • 30. #SQLSAT777 Simple Filter Imagine that you have this filter context This filter is simplified as the intersection of single-column filter if any filter can be simplified as the intersection of the individual column filters then we call it a simple filter (filter equivalency) Year MonthName 2013 April 2012 May Year 2013 2012 MonthName April May
  • 31. #SQLSAT777 Arbitrarily shaped set by UI • simple filters are good because they don’t create any problem at all • there are also filters that cannot be simplified this filter cannot be simplified. You cannot express this filter as the intersection of the individual column filters. Year MonthName 2013 April 2012 May Year 2013 2012 MonthName April May This arbitrarily shaped cannot be created as one filter on the year and another one on the month!!!
  • 32. #SQLSAT777 Problem with Arbitrarily shaped set Measure than compute the average of sales at the month granularity Why is the Total wrong? In the next slide you will see what happens is the interaction between arbitrarily shaped sets and context transition and the operators in calculate
  • 33. #SQLSAT777 Problem with Arbitrarily shaped set 1. In Total there is an iteration. For each month we compute the monthly sales. 2. During 1 iteration the selected month is April and the original filter context contain 2013 April, 2012 May. Calculate through context transition will use overwrite that remove MonthName by Original Filter context 3. Each iteration is not computing the sales of a single month but the sales of 2 year together, and the average was much higher: OVERWRITE destroy arbitrarily shape set Year MonthName 2013 April 2012 May MonthName April MonthName April Year 2013 2012
  • 34. #SQLSAT777 Year MonthName 2013 April 2012 May Year MonthName 2013 April 2012 May Solution with Arbitrarily shaped set KEEPFILTER modify the behaviour of CALCULATE when the context transition happening during iterations if there is a context transition and invoke CALCULATE, don’t use OVERWRITE, instead use INTERSECT (used as a top level function) KEEPFILTER preserve arbitrarily shape set!!! MonthName April MonthName April
  • 35. #SQLSAT777 Be careful to the SUMMARIZE • Is the only function in DAX that create at the same time a row context and filter context and both are working togheter • The reason why sometime SUMMARIZE returns strange values it’s: • the row context created by SUMMARIZE will be subject to context transaction whenever you call a measure from inside your code • And context transition use remove and is able to destroy arbitrarily sets (model,color) Row context on Test[Color] Filter context on Test[Color] Model Color Bike Blue Model Color Bike Green shirt Green Model Color Bike Red shirt Red Model Color Bike Model Color Bike shirt Model Color Bike shirt
  • 36. #SQLSAT777 Recap: Arbitrarily shaped set • not use SUMMARIZE to compute anything!!! • Use it to do a grouping by • But whenever you want to compute some values use ADDCOLUMNS instead. • ADDCOLUMNS is not subject to this behavior ☺ • KEEPFILTER preserve arbitrary shaped set
  • 38. #SQLSAT777 Understanding what ALLSELECTED does ALLSELECTED Obtain visual totals (that is the total that the user is looking at) in queries. • Removes filters context from columns and rows in the current query, • Retaining all other filters context • Retaining explicit filters context (when use CALCULATE) It’s true if and only if no iteration is happening!!!!
  • 39. #SQLSAT777 Understanding shadow filter context • Special filter context created by iterators which is always inactive except for certain situations • The DAX above generates a shadow filter context that contains the values of Product[Color] in the current filter context or explicit filter context when iterator starts. (It is inactive) • The shadow filter context is activated by ALLSELECTED!!!
  • 40. #SQLSAT777 ALLSELECTED(Column) is a table function • no shadow context to activate (no previous shadow context) because ALLSELECTED is contained in CONCATENATEX that creates a shadow contex • ALLSELECTED works on filter context but when a column is used as parameter it ignores the cross filters. The result is that Product[Product] contains all values. Brand Color Product Contoso Red Bike Contoso Green Helmet Contoso Blue Shoes Tailspin Toys Red Robot Tailspin Toys Green Shirt Tailspin Toys Blue Rollerblades Fabrikam Red Motorbike Fabrikam Green Keyboard Fabrikam Blue Piano
  • 41. #SQLSAT777 ALLSELECTED(Column) is a table function • ADDCOLUMNS creates a shadow context (shadow context 1), which is the result of VALUES() in the defined filter context when iterator starts ("Contoso","Fabrikam" ) • CONCATENATEX creates another shadow context (shadow context 2) and ALLSELECTED activates and uses the last shadow context, which is shadow context 1 Brand Contoso Fabrikam Brand Color Contoso Red Contoso Green Contoso Blue Tailspin Toys Red Tailspin Toys Green Tailspin Toys Blue Fabrikam Red Fabrikam Green Fabrikam Blue
  • 42. #SQLSAT777 ALLSELECTED(Table) is a table function • No shadow context to activate (no previous shadow context), ALLSELECTED is contained in CONCATENATEX which creates a shadow context (that remains unactive) • When a table is the parameter the cross filters are considered as opposed to when a column is used as a parameter Brand Color Product Contoso Red Bike Contoso Green Helmet Contoso Blue Shoes Tailspin Toys Red Robot Tailspin Toys Green Shirt Tailspin Toys Blue Rollerblades Fabrikam Red Motorbike Fabrikam Green Keyboard Fabrikam Blue Piano
  • 43. #SQLSAT777 ALLSELECTED(Table) is a table function • ADDCOLUMNS creates a shadow context with ALL(Product[Color]) (shadow Context 1) • CONCATENATEX creates another shadow context (shadow context 2) and ALLSELECTED activates and uses the last shadow context, which is shadow context 1 for [Color], plus the original filter on Brands Brand Color Product Contoso Red Bike Contoso Green Helmet Contoso Blue Shoes Tailspin Toys Red Robot Tailspin Toys Green Shirt Tailspin Toys Blue Rollerblades Fabrikam Red Motorbike Fabrikam Green Keyboard Fabrikam Blue Piano
  • 44. #SQLSAT777 Brand Color Product Quantity Contoso Red Bike 10 Contoso Green Helmet 20 Contoso Blue Shoes 30 Tailspin Toys Red Robot 40 Tailspin Toys Green Shirt 50 Tailspin Toys Blue Rollerbla des 60 Fabrikam Red Motorbi ke 70 Fabrikam Green Keyboar d 80 Fabrikam Blue Piano 90 ALLSELECTED() is a CALCULATE modifier • No shadow context to activate (no previous shadow context), ALLSELECTED performs ALLSELECTED on all columns, the filter context is used.
  • 45. #SQLSAT777 ALLSELECTED() is a CALCULATE modifier • Using ALLSELECTED as a CALCULATE filter argument means transforming a shadow filter context into an explicit filter context • ALLSELECTED activates and uses a shadow filter context that contains ALL [Brand] and this is the new explicit filter context, SUM is computed on all brand (60 + 150 + 210 = 450) and then this computation is repeated by SUMX 3 times (one for each brand) Brand Color Product Quantity Contoso Red Bike 10 Contoso Green Helmet 20 Contoso Blue Shoes 30 Tailspin Toys Red Robot 40 Tailspin Toys Green Shirt 50 Tailspin Toys Blue Rollerblades 60 Fabrikam Red Motorbike 70 Fabrikam Green Keyboard 80 Fabrikam Blue Piano 90
  • 46. #SQLSAT777 Recap ALLSELECTED ALLSELECTED(<Table>) • Applies the last available shadow filter context, on any column that has one • In absence of shadow context the defined (normal) filter context is used • Cross filters are considered ALLSELECTED(<Column>) • Applies the last available shadow filter context on the given column • In absence of shadow context to apply, all the column values are returned • Cross filters are not considered ALLSELECTED() • Behaves as if all the columns are used as parameter • Applies the last available shadow filter context on all the columns • In absence of shadow context to apply, all the column values are returned • Cross filters are not considered