EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB20062: In what kind of report does a report limit produce a different result from a metric qualification in MicroStrategy SQL Generation Engine?


Community Admin

• Strategy


Report limits and metric qualifications often return the same results, as noted in the following Strategy Knowledgebase document.
 
KB20060 (KB5200-8X-2444): What is the difference between a report filter and a report limit in Strategy SQL Generation Engine 8.x?
Certain scenarios, usually involving metrics at multiple levels in the same report, may behave differently depending on whether a metric condition is included in the report as a metric qualification or a report limit. Following is an example of such a report.
 
In the Strategy Tutorial project, a user wants to see the Categories and Subcategories with the highest percentage of Subcategory revenue relative to the whole Category, showing the Subcategory revenue, Category revenue and percent contribution for each. The Subcategory with the top contribution to the Category will be evaluated using a ranking qualification on the Contribution metric, yielding the top 1 rank, breaking by Category.
 
Compare the following report designs and results:
 
 

 
Sorting TypeDescriptionAttribute Form SortSort by attribute formAttribute Default SortUse the attribute default sort as the sorting key. KB16623: How does MicroStrategy resolve the default sort order for an attribute)?Metric SortSort by metric valueMetric Hierarchical SortA variant of metric sorting, where sorting is applied to subtotal levels.Subtotal Position in SortDetermines the position of subtotal(s) in sorting, thus metric sorting can be applied without mixing the subtotal rows.LanguageValueEnglishL0009ItalianL0010PortugueseL0016GermanL0007SpanishL000AJapaneseL0011KoreanL0012ChineseL0004SwedishL001DFrenchL000C ConsolidationsCustom groupsDerived elementsSupportYesYesYesCommentCan be used with all features.Can be be used with all features (even those not available when editing / creating over Web).Can be used with all features. ConsolidationsCustom groupsDerived elementsSupportNoPartiallyYesCommentCannot be created nor modified at all.Can be created / modified over web with some features limited.Can be created over web on any report (IC / schema based) with full functionality. ConsolidationsCustom groupsDerived elementsSupportNoNoYesCommentCannot be performed (neither in both Developer and Web)Cannot be performed .Can be saved at a report only. Always in the Web, in Developer only for IC based reports ConsolidationsCustom groupsDerived elementsSupportNoNoYesCommentIC cannot contain consolidations and neither reports based on an ICIC cannot contain custom groups and neither reports based on an ICSupported. Derived element cannot be directly defined on the IC template however. It can be created as standalone object and attached to the report based on the intelligent cube. ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentConsolidations can support distinct count metricsCustom groups can support distinct count metricsDerived elements do not support distinct count metrics ConsolidationsCustom groupsDerived elementsSupportNoYesNoCommentThere is no native buildin functionality.Custom groups have native support of banding and ranking functionality.There is no native buildin functionality. ConsolidationsCustom groupsDerived elementsSupportYesNoYesCommentFull support in DeveloperNo support.Full support in Web ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentSeparate column(s) with extensive formatting optionSeparate column supportedNo separate column ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentYou can use multiple attribute elements to create a groupFull supportYou cannot create one group based on multiple attributes ConsolidationsCustom groupsDerived elementsSupportNoYesYesCommentNot possible at allFull supportFull support ConsolidationsCustom groupsDerived elementsSupportNoPartiallyYesCommentNot possible at allMay be problematicFull support ConsolidationsCustom groupsDerived elementsSupportYesYesYesCommentCan be created.Can be created.Can be created. ConsolidationsCustom groupsDerived elementsDB resources & processing timeLowLow to mediumNone ConsolidationsCustom groupsDerived elementsSupportYesYesYesCommentCan be created with all features.Can be created with all features.Can be created in most cases, see "On the fly" creation for more details ConsolidationsCustom groupsDerived elementsSupportYesYesPartiallyCommentCan be used with all features.Can be used with all featuresCan be used in some cases ConsolidationsCustom groupsDerived elementsSupportNoYesNoCommentCannot be created nor modifiedFull supportCannot be created nor modified ConsolidationsCustom groupsDerived elementsSupportYesNoNoCommentCan be referencedCannot be doneCannot be done ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentCan be used in both report and view filterCan be used in both report and view filterCannot be added and used in report/view filterReport with metric qualificationReport with report limit

 
Sorting TypeDescriptionAttribute Form SortSort by attribute formAttribute Default SortUse the attribute default sort as the sorting key. KB16623: How does MicroStrategy resolve the default sort order for an attribute)?Metric SortSort by metric valueMetric Hierarchical SortA variant of metric sorting, where sorting is applied to subtotal levels.Subtotal Position in SortDetermines the position of subtotal(s) in sorting, thus metric sorting can be applied without mixing the subtotal rows.LanguageValueEnglishL0009ItalianL0010PortugueseL0016GermanL0007SpanishL000AJapaneseL0011KoreanL0012ChineseL0004SwedishL001DFrenchL000C ConsolidationsCustom groupsDerived elementsSupportYesYesYesCommentCan be used with all features.Can be be used with all features (even those not available when editing / creating over Web).Can be used with all features. ConsolidationsCustom groupsDerived elementsSupportNoPartiallyYesCommentCannot be created nor modified at all.Can be created / modified over web with some features limited.Can be created over web on any report (IC / schema based) with full functionality. ConsolidationsCustom groupsDerived elementsSupportNoNoYesCommentCannot be performed (neither in both Developer and Web)Cannot be performed .Can be saved at a report only. Always in the Web, in Developer only for IC based reports ConsolidationsCustom groupsDerived elementsSupportNoNoYesCommentIC cannot contain consolidations and neither reports based on an ICIC cannot contain custom groups and neither reports based on an ICSupported. Derived element cannot be directly defined on the IC template however. It can be created as standalone object and attached to the report based on the intelligent cube. ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentConsolidations can support distinct count metricsCustom groups can support distinct count metricsDerived elements do not support distinct count metrics ConsolidationsCustom groupsDerived elementsSupportNoYesNoCommentThere is no native buildin functionality.Custom groups have native support of banding and ranking functionality.There is no native buildin functionality. ConsolidationsCustom groupsDerived elementsSupportYesNoYesCommentFull support in DeveloperNo support.Full support in Web ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentSeparate column(s) with extensive formatting optionSeparate column supportedNo separate column ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentYou can use multiple attribute elements to create a groupFull supportYou cannot create one group based on multiple attributes ConsolidationsCustom groupsDerived elementsSupportNoYesYesCommentNot possible at allFull supportFull support ConsolidationsCustom groupsDerived elementsSupportNoPartiallyYesCommentNot possible at allMay be problematicFull support ConsolidationsCustom groupsDerived elementsSupportYesYesYesCommentCan be created.Can be created.Can be created. ConsolidationsCustom groupsDerived elementsDB resources & processing timeLowLow to mediumNone ConsolidationsCustom groupsDerived elementsSupportYesYesYesCommentCan be created with all features.Can be created with all features.Can be created in most cases, see "On the fly" creation for more details ConsolidationsCustom groupsDerived elementsSupportYesYesPartiallyCommentCan be used with all features.Can be used with all featuresCan be used in some cases ConsolidationsCustom groupsDerived elementsSupportNoYesNoCommentCannot be created nor modifiedFull supportCannot be created nor modified ConsolidationsCustom groupsDerived elementsSupportYesNoNoCommentCan be referencedCannot be doneCannot be done ConsolidationsCustom groupsDerived elementsSupportYesYesNoCommentCan be used in both report and view filterCan be used in both report and view filterCannot be added and used in report/view filterReport with metric qualificationReport with report limit

 

 

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

In both reports, the condition is defined as follows. Category is selected as the "Break by" attribute. The report limit editor is very similar, except that the options "Set Qualification Type," "Output Level" and "Advanced" are not shown because they are valid only for metric qualifications.
 

ka04W000000OenoQAC_0EM440000002EgK.gif

 

ka04W000000OenoQAC_0EM440000002Nn0.png

 
Result with metric qualification

ka04W000000OenoQAC_0EM440000002Egc.gif

 
Result with report limit

ka04W000000OenoQAC_0EM440000002EgY.gif

 
In the report that uses the metric qualification, the Category Revenue metric actually returns the revenue for the top-ranking Subcategory within the Category, same as the report-level Revenue metric. Consequently, the contribution is 100% for all rows, which is not the desired analysis.
 
Explanation of the discrepancy
In both reports, the metric condition identifies the highest-ranking Subcategory in each Category. The difference is that the ranking qualification in the report filter evaluates first and applies subsequently to all template metrics, while the report limit evaluates last, after the Category Revenue and Contribution metrics have already been calculated.
 
 

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

In the metric qualification report, the Category-level metric is subject to the set of attribute elements identified in the report filter. Since the ranking qualification allows only one Subcategory per Category, the filtered Category-level metric can be no higher than the value for the Subcategory. By contrast, the report limit merely discards the final result rows for lower-ranking Subcategories. The Category-level revenue has already been calculated including the entire Category and is not affected by the metric limit.
 
 

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

 
Metric qualification procedureReport limit procedureCalculate each Subcategory's rank within its Category Create an intermediate table with the top ranking Subcategory for each CategoryCalculate the Subcategory-level revenue, including only the Subcategories passing through the filterCalculate the Subcategory-level revenue over all SubcategoriesCalculate the Category-level revenue, including only the Subcategories passing through the filterCalculate the Category-level revenue over all categoriesJoin the metrics and calculate the contributionJoin the metrics and calculate the contribution Select the final result rows where the rank of contribution is exactly 1Metric qualification SQLReport limit SQL

Ranking qualification; #ZZMQ03 is the set of Subcategories
select a11.SUBCAT_ID SUBCAT_ID,
   sum(a11.TOT_DOLLAR_SALES) Revenue
into #ZZMD00
from CITY_SUBCATEG_SLS a11
group by a11.SUBCAT_ID

select a11.CATEGORY_ID CATEGORY_ID,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
into #ZZMD01
from YR_CATEGORY_SLS a11
group by a11.CATEGORY_ID

select pa13.CATEGORY_ID CATEGORY_ID,
   pa11.SUBCAT_ID SUBCAT_ID,
   rank () over (partition by pa13.CATEGORY_ID order by ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) desc) WJXBFS1
into #ZZAM02
from #ZZMD00 pa11
   join LU_SUBCATEG a12
      on (pa11.SUBCAT_ID = a12.SUBCAT_ID)
   join #ZZMD01 pa13
      on (a12.CATEGORY_ID = pa13.CATEGORY_ID)

select pa11.CATEGORY_ID CATEGORY_ID,
   pa11.SUBCAT_ID SUBCAT_ID
into #ZZMQ03
from #ZZAM02 pa11
where (pa11.WJXBFS1 <= 1.0)
 

Ranking qualification; #ZZMQ03 is the set of Subcategories
select a11.SUBCAT_ID SUBCAT_ID,
   sum(a11.TOT_DOLLAR_SALES) Revenue
into #ZZMD00
from CITY_SUBCATEG_SLS a11
group by a11.SUBCAT_ID

select a11.CATEGORY_ID CATEGORY_ID,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
into #ZZMD01
from YR_CATEGORY_SLS a11
group by a11.CATEGORY_ID

select pa13.CATEGORY_ID CATEGORY_ID,
   pa11.SUBCAT_ID SUBCAT_ID,
   rank () over (partition by pa13.CATEGORY_ID order by ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) desc) WJXBFS1
into #ZZAM02
from #ZZMD00 pa11
   join LU_SUBCATEG a12
      on (pa11.SUBCAT_ID = a12.SUBCAT_ID)
   join #ZZMD01 pa13
      on (a12.CATEGORY_ID = pa13.CATEGORY_ID)

select pa11.CATEGORY_ID CATEGORY_ID,
   pa11.SUBCAT_ID SUBCAT_ID
into #ZZMQ03
from #ZZAM02 pa11
where (pa11.WJXBFS1 <= 1.0)
 

Template metrics; set qualification applies at Subcategory level
select a11.SUBCAT_ID SUBCAT_ID,
   sum(a11.TOT_DOLLAR_SALES) Revenue
into #ZZMD04
from CITY_SUBCATEG_SLS a11
   join #ZZMQ03 pa12
      on (a11.SUBCAT_ID = pa12.SUBCAT_ID)
group by a11.SUBCAT_ID

select pa12.CATEGORY_ID CATEGORY_ID,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
into #ZZMD05
from CITY_SUBCATEG_SLS a11
   join #ZZMQ03 pa12
      on (a11.SUBCAT_ID = pa12.SUBCAT_ID)
group by pa12.CATEGORY_ID

Calculate Revenue at Subcategory and Category levels; no filter
select a11.SUBCAT_ID SUBCAT_ID,
   sum(a11.TOT_DOLLAR_SALES) Revenue
into #ZZMD00
from CITY_SUBCATEG_SLS a11
group by a11.SUBCAT_ID

select a11.CATEGORY_ID CATEGORY_ID,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
into #ZZMD01
from YR_CATEGORY_SLS a11
group by a11.CATEGORY_ID

Join results
select pa13.CATEGORY_ID CATEGORY_ID,
   a14.CATEGORY_DESC CATEGORY_DESC,
   pa11.SUBCAT_ID SUBCAT_ID,
   a12.SUBCAT_DESC SUBCAT_DESC,
   pa11.Revenue Revenue,
   pa13.WJXBFS1 WJXBFS1,
   ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) WJXBFS2
from #ZZMD04 pa11
   join LU_SUBCATEG a12
      on (pa11.SUBCAT_ID = a12.SUBCAT_ID)
   join #ZZMD05 pa13
      on (a12.CATEGORY_ID = pa13.CATEGORY_ID)
   join LU_CATEGORY a14
      on (pa13.CATEGORY_ID = a14.CATEGORY_ID)

drop table #ZZMD00
drop table #ZZMD01
drop table #ZZAM02
drop table #ZZMQ03
drop table #ZZMD04
drop table #ZZMD05

Join results; calculate Contribution and rank
select pa13.CATEGORY_ID CATEGORY_ID,
   a14.CATEGORY_DESC CATEGORY_DESC,
   pa11.SUBCAT_ID SUBCAT_ID,
   a12.SUBCAT_DESC SUBCAT_DESC,
   pa11.Revenue Revenue,
   pa13.WJXBFS1 WJXBFS1,
   ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) WJXBFS2,
   rank () over (partition by pa13.CATEGORY_ID order by ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) desc) WJXBFS3
into #ZZAM02
from #ZZMD00 pa11
   join LU_SUBCATEG a12
   on (pa11.SUBCAT_ID = a12.SUBCAT_ID)
   join #ZZMD01 pa13
   on (a12.CATEGORY_ID = pa13.CATEGORY_ID)
   join LU_CATEGORY a14
   on (pa13.CATEGORY_ID = a14.CATEGORY_ID)

Keep only top-ranking rows without affecting metric results
select pa11.CATEGORY_ID CATEGORY_ID,
   pa11.CATEGORY_DESC CATEGORY_DESC,
   pa11.SUBCAT_ID SUBCAT_ID,
   pa11.SUBCAT_DESC SUBCAT_DESC,
   pa11.Revenue WJXBFS1,
   pa11.WJXBFS1 WJXBFS2,
   pa11.WJXBFS2 WJXBFS3
from #ZZAM02 pa11
where (pa11.WJXBFS3 <= 1.0)

drop table #ZZMD00
drop table #ZZMD01
drop table #ZZAM02

Absolute filtering as an alternative to the report limit in this scenario
The metric qualification obtains this result because the Category-level and Contribution metrics specify standard filtering at the level of Category. The metric qualification at report level is evaluated at the level of Subcategory, and this is the level that applies to higher-level metrics as well.
 
If, instead, the Category and Contribution metrics use Absolute filtering at Category level, then the metric qualification returns the same result as the report limit. The metric condition still applies before aggregating template metrics, but the Category-level metric "raises" the Subcategory filter up to Category. Where the Subcategory is "Science & Technology," an absolute-filtered metric calculates over the entire Books category and the final result is as desired.
 
SQL using Absolute filtering
 
Ranking qualification; #ZZMQ03 is the set of Subcategories
select a11.SUBCAT_ID SUBCAT_ID,
   sum(a11.TOT_DOLLAR_SALES) Revenue
into #ZZMD00
from CITY_SUBCATEG_SLS a11
group by a11.SUBCAT_ID
select a11.CATEGORY_ID CATEGORY_ID,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
into #ZZMD01
from YR_CATEGORY_SLS a11
group by a11.CATEGORY_ID
select pa13.CATEGORY_ID CATEGORY_ID,
   pa11.SUBCAT_ID SUBCAT_ID,
   rank () over (partition by pa13.CATEGORY_ID order by ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) desc) WJXBFS1
into #ZZAM02
from #ZZMD00 pa11
   join LU_SUBCATEG a12
      on (pa11.SUBCAT_ID = a12.SUBCAT_ID)
   join #ZZMD01 pa13
      on (a12.CATEGORY_ID = pa13.CATEGORY_ID)
select pa11.CATEGORY_ID CATEGORY_ID,
   pa11.SUBCAT_ID SUBCAT_ID
into #ZZMQ03
from #ZZAM02 pa11
where (pa11.WJXBFS1 <= 1.0)
Subcategory-level Revenue; set qualification applies at Subcategory level
select a11.SUBCAT_ID SUBCAT_ID,
   sum(a11.TOT_DOLLAR_SALES) Revenue
into #ZZMD04
from CITY_SUBCATEG_SLS a11
   join #ZZMQ03 pa12
      on (a11.SUBCAT_ID = pa12.SUBCAT_ID)
group by a11.SUBCAT_ID
Category-level Revenue; set of Subcategories is converted to whole Categories
select a11.CATEGORY_ID CATEGORY_ID,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
into #ZZMD05
from YR_CATEGORY_SLS a11
where ((a11.CATEGORY_ID)
   in (select ps21.CATEGORY_ID
      from #ZZMQ03 ps21))
group by a11.CATEGORY_ID
Join results
select pa13.CATEGORY_ID CATEGORY_ID,
   a14.CATEGORY_DESC CATEGORY_DESC,
   pa11.SUBCAT_ID SUBCAT_ID,
    a12.SUBCAT_DESC SUBCAT_DESC,
   pa11.Revenue Revenue,
   pa13.WJXBFS1 WJXBFS1,
   ISNULL((pa11.Revenue / NULLIF(pa13.WJXBFS1, 0)), 0) WJXBFS2
from #ZZMD04 pa11
   join LU_SUBCATEG a12
      on (pa11.SUBCAT_ID = a12.SUBCAT_ID)
   join #ZZMD05 pa13
      on (a12.CATEGORY_ID = pa13.CATEGORY_ID)
   join LU_CATEGORY a14
      on (pa13.CATEGORY_ID = a14.CATEGORY_ID)
drop table #ZZMD00
drop table #ZZMD01
drop table #ZZAM02
drop table #ZZMQ03
drop table #ZZMD04
drop table #ZZMD05
The results of this SQL (using absolute filtering) exactly match the results shown above for the report limit. It is a matter of thinking about the level at which the ranking qualification should apply. For this reporting requirement, applying the ranking set at report level is incorrect; instead, that set should be raised to Category level.
 


Comment

0 comments

Details

Knowledge Article

Published:

June 5, 2017

Last Updated:

June 5, 2017