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
  3. KB6369: How Does the Percentile Function Calculate Values in MicroStrategy Engine

KB6369: How Does the Percentile Function Calculate Values in MicroStrategy Engine


Stefan Zepeda

Salesforce Solutions Architect • Strategy


This article describes how the Percentile function works in MicroStrategy

The following equation can be used to show how the Percentile function calculates the numeric value in MicroStrategy Engine:

  • n = highest rank value
  • P = percent value
  • rank1 = lower value percent
  • rank2 = upper value percent
  • x = physical percentile value for which users are solving.

[(P*n) - rank1] / [rank2 - rank1] = [x - (metric value @ rank1)] / [(metric value @ rank2) - (metric value @ rank1)]

[(P*n) - rank1] / [rank2 - rank1] * [(metric value @ rank2) - (metric value @ rank1)] = x - (metric value @ rank1)

x = [(P*n) - rank1] / [rank2 - rank1] * [(metric value @ rank2) - (metric value @ rank1)] + (metric value @ rank1)

Rank1 and Rank2 are determined by first assigning percentage values to each rank according to the linear formula Rank(i) / n, where the ranks begin with 0 and n is the highest rank. For instance, if there are five metric values, they would be ranked as 0, 1, 2, 3, and 4, and the assigned percentage values would be (0..4) / 4, or 0, 0.25, 0.5, 0.75 and 1.

 

P, the percentage specified in the percentile function, must fall between the percentages assigned to Rank1 and Rank2. That is, if P is 40% or 0.4, the assigned percentages surrounding that value are 0.25 and 0.5. Thus Rank1 would be 1 and Rank2 would be 2. P*n would be 0.4 x 4, or 1.6.

 

The remainder of the formula performs a simple linear interpolation, in which the proportion of the input percentage to its assigned neighbors is the same as the proportion of the output value to its neighboring metric values.

 

If P = 0.4, (P - 0.25) / (0.5 - 0.25) = 3/5, so x should be 3/5 of the way between 30 and 60, or 48. Thus 40% of the metric values would be expected to be less than 48.
ka04W00000147wNQAQ_0EM440000002GBo.gif
The following is an example of how the percentile function can be used in the MicroStrategy Tutorial project:
  1. Create a metric that is the sum of the fact 'Revenue.'
ka04W00000147wNQAQ_0EM440000002GBY.gif

Create a second metric that is the Rank of the first metric -1. The reason the metric needs to subtract one is that the Percentile function starts its calculation from zero and not from one in regards to the ranking. The second metric should have the following rank parameters. Also, make sure the metric format is set to fixed with zero decimal places.

ka04W00000147wNQAQ_0EM440000002GBG.gif

On the Revenue fact, determine which table will be referenced, either by running a small report or looking at the logical table size of each source table in the fact definition.

ka04W00000147wNQAQ_0EM440000002GBM.gif

In this example the smallest table is YR_CATEGORY_SLS. Since there are two keys in this table, the template should contain at least these two keys. The following template contains metrics #1 and #2 above and the attributes 'Year' and 'Category'.

ka04W00000147wNQAQ_0EM440000002GBm.gif

The report returns the following data when executed.

ka04W00000147wNQAQ_0EM440000002GBj.gif

This data can be sorted by rank by going to Data > Advanced sorting and adding the metric to the sort properties.

ka04W00000147wNQAQ_0EM440000002GBK.gif

  1. Export this report to Excel and create a new column called 'Percentage'. The formula for this new column is Rank of Dollar Sales/ highest rank number (n). In this example, the highest rank number is six. This provides the values to plug into the percentile formula.

 

 

 

 

Metrics

Sum of Dollar Sales

Rank of Dollar Sales by Year

Percentage

Year

Category

 

 

 

 

 

Kid's Korner

 

2,559

0

0

 

Travel

 

4,497

1

0.166666667

 

Food

 

5,300

2

0.333333333

1997

Health & Beauty

 

6,042

3

0.5

 

Electronics

 

10,616

4

0.666666667

 

Gifts

 

16,315

5

0.833333333

 

Household

 

38,383

6

1

 

Kid's Korner

 

2,943

0

0

 

Travel

 

4,792

1

0.166666667

 

Food

 

5,638

2

0.333333333

1998

Health & Beauty

 

5,665

3

0.5

 

Gifts

 

20,047

4

0.666666667

 

Electronics

 

29,299

5

0.833333333

 

Household

 

50,391

6

1

 

 

  1. Create a new metric which is the 40th percentile of the fact 'Dollar Sales'
ka04W00000147wNQAQ_0EM440000002GBI.gif

Create a new report with the 40th percentile metric and the attribute 'Year'.

ka04W00000147wNQAQ_0EM440000002GBh.gif

This report returns the following results:

ka04W00000147wNQAQ_0EM440000002GBk.gif
Plugging the numbers into the percentile formula validates the calculation.

[(P*n) - rank 1] / [rank2 - rank 1] = [x - (numeric value @ rank1)] / [(numeric value @ rank2) - (numeric value @ rank1)]
[(.4*6) - 2] / [3- 2] = [x - (5300)] / [6042 - 5300]
0.4 / 1 = (x - 5300) / 742
0.4 * 742 = x - 5300
296.8 = x - 5300
x = 5596.8

 

 

Note for data with tied ranks:
 The dataset in the example above does not include any tied values (which would be given the same rank value when using the MicroStrategy Rank function). If tied values are encountered in the dataset when using the MicroStrategy Percentile function, the rank values assigned to them would not be identical. The tied values will be ranked progressively in the order they are returned in the dataset and the resulting percentile calculation will reflect this rank calculation. The values obtained using the percentile calculation in MicroStrategy should match the values obtained using the Microsoft Excel percentile function over the same dataset.

Consider the example used above. If both the 'Food' and the 'Health & Beauty' categories for the year 1998 have the same value for 'Sum of Dollar Sales', the rank displayed for category in the report shown in step 6. would be the same '2' and the rank for category 'Gifts' would be '4'.

However when calculating the percentile value, the rank assigned to 'Food' would be '2' and the rank assigned to 'Health & Beauty' would be '3' even though the metric values are the same.


Comment

0 comments

Details

Knowledge Article

Published:

June 28, 2023

Last Updated:

January 31, 2024