Normal Behaviour | Auto Exists | Exists | Existing | |
Theory | When the two sets are cross joined it will produce all possible combination. E.g. if we join two sets with 4 dimension each then it will produce 16 members | It forces the natural hierarchy in the below Scenarios
| It forces the natural hierarchy with out returning the forcing/second set | Auto exist is not applicable to calculated members and if we want to force this behaviour then we need existing keyword |
When to use | When we want to display the measures based on two different dimension | When we want to display the measures based on the members in different level from same hierarchy | Achieve the same Auto exists results with out displaying second Dimension | Forces the local context in the calculated members |
Normal Behaviour
Run the below query
SELECT [Measures].[Reseller Sales Amount] ON 0
, [Product].[Category].[Category].Members on 1
from [Adventure Works]
Based on the above query we have 4 Categories in the Product Categories Hierarchy
SELECT [Measures].[Reseller Sales Amount] ON 0
, [Geography].[Geography].[Country].members
on 1
from [Adventure Works]
Based on the above query we have 6 countries under geography hierarchy
Let us Cross Join it
SELECT [Measures].[Reseller Sales Amount] ON 0
,[Product].[Category].[Category].Members
* {[Geography].[Geography].[Country].Members
} on 1
from [Adventure Works]
So along with the header row it has returned 25 rows which is direct cross product of 4 Products and 6 countries (24 data row + 1 Header row)
What other ways to achieve the cross join
You can use the cross join function as shown below
SELECT [Measures].[Reseller Sales Amount] ON 0
,crossjoin ([Product].[Category].[Category].Members
, [Geography].[Geography].[Country].Members
) on 1
from [Adventure Works]
Even if you remove the Crossjoin keyword in the above query, it will still produce the same result .
,([Product].[Category].[Category].Members
, [Geography].[Geography].[Country].Members
) on 1
from [Adventure Works]
Auto Exists
In the above example we have used the cross join between two different hierarchies (Product.category and geography.country). let us join between category and sub category from same product hierarchy.
Step 1: Let us find the count of subcategory first
SELECT [Measures].[Reseller Sales Amount] ON 0
, [Product].[SubCategory].[SubCategory].Members on 1
from [Adventure Works]
SELECT [Measures].[Reseller Sales Amount] ON 0
, [Product].[Category].[Category].Members *
[Product].[Subcategory].[Subcategory].Members on 1
from [Adventure Works]
As you can see from the output though it has given the cross product, it still only has the same 38 (37 rows of data + 1 header) rows in the output. as per the normal behaviour it should be 4*38 = 152
What is Existing
with member countofsubcategory as
count( [Product].[Subcategory].[Subcategory].Members)
SELECT {[Measures].[Reseller Sales Amount], countofsubcategory} ON 0
, [Product].[Category].[Category].Members *
[Product].[Subcategory].[Subcategory].Members
on 1
from [Adventure Works]
with member countofsubcategory as
count( existing [Product].[Subcategory].[Subcategory].Members)
SELECT {[Measures].[Reseller Sales Amount], countofsubcategory} ON 0
, [Product].[Category].[Category].Members *
[Product].[Subcategory].[Subcategory].Members
on 1
from [Adventure Works]
What is Exists function ?
Exists uses the “Auto exist” functionality but avoid displaying the “second set” in the results
No comments:
Post a Comment