
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to make Expression into parameterized function/variable
Hey, I'm hoping someone can help me with the below.
So I have this expression, which winsorizes some data, and works well.
Avg(
Coalesce(
if( price< $(=Fractile(price,0.05)), $(=Fractile(price,0.05))),
if( price> $(=Fractile(price,0.95)), $(=Fractile(price,0.95))),
price
)
);
For the life of me I cannot turn this into a parameterized variable. I tried creating the below in my load script:
Set fWeightedAvgTest8 =
Avg(
Coalesce(
if( $1 < Fractile($1,$2), Fractile($1,$2)),
if( $1 > Fractile($1,$3), Fractile($1,$3)),
$1
)
);
And calling it in my script like this:
$(fWeightedAvgTest8(price, 0.05, 0.95))
But it doesn't work, it says Nested aggregation not allowed.
I also tried like this
Set fWeightedAvgTest6 =
Avg(
Coalesce(
if( $1 < '=Fractile($1,$2)', '=Fractile($1,$2)'),
if( $1 > '=Fractile($1,$3)', '=Fractile($1,$3)'),
$1
)
);
When calling it in the script, it says OK, but the KPI that has that expression is blank.
Any help would be much appreciated! Thanks!
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @johnnyjohn , one option is put variables inside the formula in the chart, like this :
Avg(Coalesce(if( price < $(=Fractile(price,$(vExp1))), $(=Fractile(price,$(vExp1)))),if( price> $(=Fractile(price,$(vExp2))), $(=Fractile(price,$(vExp2)))), price))
The variables can be created in script :
Set vExp1 = 0.05;
Set vExp2 = 0.95;
and then in layout you can change the variables values in input boxes :
And if you want to test creating and using a formula just in the script execution, youcan create functions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @johnnyjohn , one option is put variables inside the formula in the chart, like this :
Avg(Coalesce(if( price < $(=Fractile(price,$(vExp1))), $(=Fractile(price,$(vExp1)))),if( price> $(=Fractile(price,$(vExp2))), $(=Fractile(price,$(vExp2)))), price))
The variables can be created in script :
Set vExp1 = 0.05;
Set vExp2 = 0.95;
and then in layout you can change the variables values in input boxes :
And if you want to test creating and using a formula just in the script execution, youcan create functions.
