Skip to main content

Hi,

How can I do a median in Pigment ?

Thanks

Hi Alexandre,

 

We don’t have a function for calculating the median right now, but you can calculate it by combining a few modifiers and functions in a formula like the one below:

rev2eRANK(rev2, Month, ASC, Sequential) IN (ROUNDDOWN((rev2eREMOVE COUNT: Country] + 1) / 2):ROUNDUP((rev2eREMOVE COUNT: Country] + 1) / 2))])REMOVE AVG: Country]

It might look a little complex, but see the below example to see it in action. We are calculating the median of the revenue across all countries for a given month.

 

Hopefully you can leverage this example for your own modelling :)
 

Cheers,


Hi, thank you for the tips! :)

 


Hey @Matt D thanks for this response.  I’m trying to do something similar but with slightly more dimensionality.  Using your example, let’s say the rev2 metric was structured by country, month, AND customer - what I’d like to do is calculate the median customer revenue amount by country & month.  My assumption is that I’m running into limitations with the “Group” portion of the RANK formula - in your example above it resets the ranking by the month dimension, but with what I’m doing I’d think it would need to reset rankings on month and country. 

Are you aware of any ways to accomplish something like this? 

EDIT: I believe I was able to find what I needed in the article on the RANK function, using a unique dimension property along with the “&” symbol to reset across multiple dimensions.  Thanks again for providing this example 

Thanks, 


Reply