Loading

Filter Top N Percent Instead of Top N

Publiseringsdato: Feb 21, 2025
Oppgave
How to display the top N percent. There are two ways to show the top N percent: number of items, or items that account for the top n% of a value.

For example, if the goal is top 20% of customers by sales then the end result could either by the top 20 customers with the highest sales (number of items) or however many customers account for 20% of total sales (items that account for top 20% of sales). If there are a few big spenders then this second scenario may be fewer than 20 customers.

 
Trinn
See the Attachments section of this article for an example workbook that uses the sample data set Superstore to demonstrate the following directions.

Scenario 1: Top N% by Number of Items

These options will return the top N% of customers sorted by sales. 

Option 1: Use level of detail (LOD) functions

LOD calculations allow for more flexibility in how the view is built, but the parameter requires manually setting all of the display values. These directions start from "Original View" in the workbook downloadable from the right-hand pane of this article. 

  1. Click the down arrow next to the search bar and select Create Parameter...
  2. In the Create Parameter dialog do the following, and click OK:
    1. Name the parameter. In this example, it's named "Select Top N Percentage (LOD)"
    2. For Data type, select Float
    3. For Display format, select Percentage
    4. For Allowable values, select Range
    5. Set Minimum to 0, Maximum to 1, Step size to .05
    6. Change Allowable values to List. This will populate the list with values
    7. Update the display values 1-N. For example, for .1 the display value should be 90%. This is necessary because the filter uses percentile, which requires the 1-N value.
  3. Select Analysis > Create Calculated Field
  4. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Top N Customers by Sales (LOD) Filter"
    2. In the formula field, create a calculation similar to the following:
      { FIXED [Customer Name] : SUM([Sales])} 
      >=
      { FIXED : 
          PERCENTILE( { FIXED [Customer Name] : SUM([Sales])}, [Select Top N Percentage (LOD)])
      }
  5. Drag [Top N Customers by Sales (LOD) Filter] to the Filters shelf
  6. In the Filter dialog, check True and click OK

Option 2: Use table calculations 

These directions start from "Original View" in the workbook downloadable from the right-hand pane of this article. 

  1. Click the down arrow next to the search bar and select Create Parameter...
  2. In the Create Parameter dialog do the following, and click OK:
    1. Name the parameter. In this example, it's named "Select Top N Percentage"
    2. For Data type, select Float
    3. For Display format, select Number (custom) and add "%" as a suffix
    4. For Allowable values, select Range
    5. Set Minimum to 0, Maximum to 100, Step size to 1
  3. Select Analysis > Create Calculated Field
  4. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Customer Rank by Sales"
    2. In the formula field, create a calculation similar to the following:
      RANK_UNIQUE(SUM([Sales]),'desc')
  5. Create a calculated field named "Top N % Customer by Sales filter (# of items, table calc)" with a formula similar to
    [Customer Rank by Sales]
    <=
    WINDOW_MAX([Customer Rank by Sales])*([Select Top N Percentage]/100)
  6. Drag [Top N % Customer by Sales filter (# of items, table calc)] to the Filters shelf
  7. In the Filter dialog check True and click OK


Scenario 2: Top N% by Value

This scenario will return the customers responsible for the top N% of sales. These directions start from "Original View" in the workbook downloadable from the right-hand pane of this article. 
  1. Click the down arrow next to the search bar and select Create Parameter...
  2. In the Create Parameter dialog do the following, and click OK:
    1. Name the parameter. In this example, it's named "Select Top N Percentage"
    2. For Data type, select Float
    3. For Display format, select Number (custom) and add "%" as a suffix
    4. For Allowable values, select Range
    5. Set Minimum to 0, Maximum to 100, Step size to 1
  3. Select Analysis > Create Calculated Field
  4. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Top N% Sales Filter"
    2. In the formula field, create a calculation similar to the following:
      RUNNING_SUM(SUM([Sales])) / TOTAL(SUM([Sales]))
      <=
      [Select Top N Percentage]/100
  5. Drag [Top N% Sales Filter] to the Filters shelf 
  6. In the Filters dialog, check True and OK
Flere ressurser
Knowledge-artikkelnummer

001458086

Vedlegg

Top N percent_v2022.1.twbx

1264 KB

 
Laster
Salesforce Help | Article