Skip to main content
Announcements
Qlik Community Office Hours - Bring your Ideation questions- May 15th, 11 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
paulwalker
Creator II
Creator II

Convert into script

HI Community,

I have many calculations in my Application.. I am using almost Aggr function in UI level.

Because i have performance  issues..

this expression working fine for me.... but How to convert into script level..???

Thanks in Advance....

1 Solution

Accepted Solutions
alex_millan
Creator III
Creator III

Hi Paul,

just in case that may help.

Try this in script:

     OriginalData:

     LOAD * Inline [

     KEY, Category, Amount

     1, 18, 10

     2, 18, 5

     3, 18, 5

     4, 22, 25

     5, 22, 12

     6, 23, 100

     ];

     TotalCategory:

     LOAD Category, Sum(Amount) As AmountCategory RESIDENT OriginalData Group by Category;

     LOAD 'TOTAL' As Category, AmountCategory; LOAD Sum(AmountCategory) As AmountCategory RESIDENT      TotalCategory;

     FactTable:

     LOAD Category, Amount, Lookup('AmountCategory','Category',Category,'TotalCategory') As AmountCategory,      Lookup('AmountCategory','Category','TOTAL','TotalCategory') As AmountTotal

     RESIDENT OriginalData;

     Drop table OriginalData;

     Drop table TotalCategory;

Using this, you will have in your fact table the total amount per category, and the absolut total amount.

Best regards.

View solution in original post

5 Replies
alex_millan
Creator III
Creator III

Hi Paul,

just in case that may help.

Try this in script:

     OriginalData:

     LOAD * Inline [

     KEY, Category, Amount

     1, 18, 10

     2, 18, 5

     3, 18, 5

     4, 22, 25

     5, 22, 12

     6, 23, 100

     ];

     TotalCategory:

     LOAD Category, Sum(Amount) As AmountCategory RESIDENT OriginalData Group by Category;

     LOAD 'TOTAL' As Category, AmountCategory; LOAD Sum(AmountCategory) As AmountCategory RESIDENT      TotalCategory;

     FactTable:

     LOAD Category, Amount, Lookup('AmountCategory','Category',Category,'TotalCategory') As AmountCategory,      Lookup('AmountCategory','Category','TOTAL','TotalCategory') As AmountTotal

     RESIDENT OriginalData;

     Drop table OriginalData;

     Drop table TotalCategory;

Using this, you will have in your fact table the total amount per category, and the absolut total amount.

Best regards.

paulwalker
Creator II
Creator II
Author

HI Alex,

My Average Expression

Sum(Total Category * Aggr(Sum(Amount), Category)) / Sum(Total Aggr(Sum(Amount), Category))

It should be 22.13

But i am not getting this value..

PFA

alex_millan
Creator III
Creator III

Hi again,

Check the attached file.

Hope that's what you need.

Best regards

alex_millan
Creator III
Creator III

Hi PaulWalker,

have you ckecked the file? Did you finally solve it?

If so, remember to close the thread by marking the answer you prefer as correct.

Cheers!

paulwalker
Creator II
Creator II
Author

Thank you