Dynamic ranking measures

The ranking measures in the previous section are specific to individual products. These measures cannot be used, for example, to rank product subcategories or product categories. Rather than develop many separate measures targeted at one specific column, logic can be embedded in DAX measures to dynamically adjust to the columns in the filter context.

In the following measure, a ranking is applied based on the filter context from three levels of a product hierarchy: 

Internet Net Sales Product Rank (Conditional) = 
VAR ProductFilter = ISFILTERED('Product'[Product Name])
VAR SubCatFilter = ISFILTERED('Product'[Product Subcategory])
VAR CatFilter = ISFILTERED('Product'[Product Category])
RETURN
Switch(TRUE(),
ProductFilter = TRUE(), RANKX(ALL('Product'[Product Name]),[Internet Net Sales],,DESC,Skip),
SubCatFilter = TRUE(), RANKX(ALL('Product'[Product Subcategory]),[Internet Net Sales],,DESC,Skip),
CatFilter = TRUE(), RANKX(ALL('Product'[Product Category]),[Internet Net Sales],,DESC,Skip),
BLANK())

The measure checks for the existence of a filter on the Product Name, Product Subcategory, and Product Category columns within a SWITCH() function via the ISFILTERED() function. The first logical condition to evaluate as true will result in the corresponding RANKX() expression being executed. If no condition is found to be true, then the BLANK() value is returned. 

The dynamic ranking measure can be used in report visuals which drill up/down through the product hierarchy or in separate visuals dedicated to specific columns. In the following screenshot, distinct table visuals representing the three levels of the product hierarchy utilize the Internet Net Sales Product Rank (Conditional) measure:

Dynamic ranking measure

For the visuals in the preceding table, a shorter and more intuitive name was used instead of the full measure name (Internet Net Sales Product Rank (Conditional)). To change the name of a measure or column used in a report visual, double-click the name of the measure or column in the Values bucket of the Visualizations pane. The revised name only applies to the specific visual, and hovering over the revised name identifies the source measure or column.

Similar to the Internet Net Sales Product Rank measure from the previous section, the conditional measure allows for other columns to impact the filter context. For example, if both the Product Category and Product Subcategory columns are included in the same table visual, the conditional measure will rank the subcategories relative to other subcategories of the same Product Category. With this dataset, the Tires and Tubes subcategory, which is ranked fourth overall per the above table, would be ranked number one for the Accessories product category. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.3.175