Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I want to calculate fractile in the script. I used the following expression that doesn't work properly. If I load the script it only returns Category 4. When I calculate fractile as a dynamic dymension the formula works properly.
Do you have any idea, what's wrong with my expression?
Cheers,
Tobias
LOAD
*,
if([Ø-Price] <= fractile(TOTAL [Ø-Price], 0.25), 1,
if([Ø-Price] <= fractile(TOTAL [Ø-Price], 0.50), 2,
if([Ø-Price] <= fractile(TOTAL [Ø-Price], 0.75), 3, 4))) as Category
You need a GROUP BY clause in your LOAD using the fractile() script aggregation function, right?
And you are grouping by all fields of your input table?
I don't think the TOTAL qualifier works in the script,
Hi Swuehl,
I have tried to apply your point including the GROUP BY clause and removing the TOTAL qualifier in my LOAD.
Doing this I get a script error stating: "Invalid Expression".
Can you the reason for this?
Thanks,
Tobias
Sales:
LOAD
PROD_MAIN_GRP_TXT,
PROD_GRP_TXT,
PROD_ID,
PROD_TXT,
MANU_TXT,
Sales,
Quantity,
COS,
Margin,
[Ø-Price]
FROM
(
Sales_Temp:
LOAD
*,
if([Ø-Price] <= fractile([Ø-Price], 0.25), 1,
if([Ø-Price] <= fractile([Ø-Price], 0.50), 2,
if([Ø-Price] <= fractile([Ø-Price], 0.75), 3, 4))) as Quantil
RESIDENT Sales
GROUP BY
PROD_MAIN_GRP_TXT,
PROD_GRP_TXT,
PROD_ID,
PROD_TXT,
MANU_TXT;
DROP Table Sales;
RENAME Table Sales_Temp to Sales;
The average price is not part of your group by clause, thus you need to aggregate the price when using it in your LOAD.
You don't do this when comparing the average price with the fractiles.
What do you want to achieve, specifically, in which context do you want to calculate the fractiles? I assume the TOTAL context across all data records.
Try maybe something like this:
Sales:
LOAD
PROD_MAIN_GRP_TXT,
PROD_GRP_TXT,
PROD_ID,
PROD_TXT,
MANU_TXT,
Sales,
Quantity,
COS,
Margin,
[Ø-Price]
FROM
(
JOIN (Sales)
LOAD
fractile([Ø-Price], 0.25) as fractile1,
fractile([Ø-Price], 0.50) as fractile2,
fractile([Ø-Price], 0.75) as fractile3
RESIDENT Sales;
Result:
NOCONCATENATE
LOAD *,
if([Ø-Preis] <= fractile1, 1,
if([Ø-Preis] <= fractile2, 2,
if([Ø-Preis] <= fractile3, 3, 4))) as Quantil
RESIDENT Sales;
Drop table Sales,
drop fields fractile1, fractile2. fractile3;
You need to include all non-aggregate expressions in the group by. Since are performing a LOAD *, you will need to add these as well:
Sales,
Quantity,
COS,
Margin
Thanks so far for your help. I try to explain what should be the final result:
I want to cluster average article sales prices of various manufacturers by product group into fractiles. The final result should be a matrix, that shows which manufacturer is offering which products in the different fractiles (price segment).
My source data is segregated by Manufacturer, Product Group and Articles. The results of your script are perfectly matching the results I get, when I did the calculation using a dynamic dimension.
But it doesn't work if I set filter e.g. by Product Group, or any other Dimension. I guess the fractiles need to be calculated for each Dimension i.e. Product Group.
Is there a "smart" way, how to do this?
You can add a group by clause with the appropriate dimensions to the script:
JOIN (Sales)
LOAD
Dim1,
Dim2,
fractile([Ø-Price], 0.25) as fractile1,
fractile([Ø-Price], 0.50) as fractile2,
fractile([Ø-Price], 0.75) as fractile3
RESIDENT Sales
GROUP BY Dim1, Dim2 ;
Replace Dim1 and Dim2 with the appropriate fields from your sales table.
Be aware that calculating these fractiles in the script prevent you from getting adjusted results when filtering records.
Maybe a UI solution (expressions in front end) would be better then.