Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Computing Expressions on Script Level

Hello All,

I have almso 20-25 expressions calculated on UI level across various Charts and Graphs for 20 Domensions (almost). The Application is getting affected because of the loading or refreshing time of charts.

I want to calculate all or may be few expressions in UI level. Please guide me accordingly.

Following are a few expressions used in UI level--

1. Annual Loss Amount - (Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>}Disitnct Annual_Loss)

2. Loss Amount Ratio - (Sum(Disitnct Annual_Loss) + Sum(Disitnct Risk_Loss) + Sum(Disitnct Settlement_Cost)) / Sum(Disitnct Premium_Amount)

3. Insurance Premium - Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>}Disitnct Policy_Premium)

4. Premium Ratio - Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>}Disitnct Policy_Premium) / Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>}Disitnct Premium_Amount)

Likewise a few more. I am thinking to write above calculations with Group By all the Dimensions.

Please suggest correct way.

Thanks in Advance.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Looks like you are aggregating things at the Year_Quarter level and this could certainly be done in the script using group by.

I am just finishing off redesigning a dashboard that displays many things at a month aggregation level.

The original had about 50 million data rows and the front end was stuffed full of horrendous expressions [albeit very cunning some of them]  and its performance was bad, plus it chewed up loads of RAM & CPU.

My new version has about 70 thousand rows and the front end only has simple expressions.  It is now lightening fast and consumes negligible RAM & CPU.  [Both cost money and CPU cycles consume electricity, making heat that needs air con cooling that takes more power that all contributes to global warming as well reducing the business's profit]

My personal general rules of thumb are :

  • If it can be done in the script then do it in the script
  • If your front end is full of over complex expressions then the data model is in need of improvement

One does need to think about what level of granularity is needed in the front end:

  • If you need to drill down to transaction level then you need to load your data at the transaction level so aggregation to a higher level would not be appropriate
  • But in my scenario the lowest level of front end drill down needed was month, so it was a perfect candidate for month level aggregation in the script
  • I also had a few other dimension to consider, such as Business Unit, Customer, Type, Function - So the group by was actually on these dimensions as well as month

But not knowing the details of your data model & needs I cannot make any definitive suggestions for your specific scenario.

View solution in original post

10 Replies
sunny_talwar

It can be easier to help if you can provide a sample to work with.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

What exactly is the meaning of all those DISTINCT keywords? Does it mean that for example for every combination of dimension values, you can have only one $500 amount?

Maybe you should first do something about your data model?

Anonymous
Not applicable
Author

I have d correct data model. Chked with ETL team. Distinct we are using because we have same figure for each location.

Customer 1 has 5 location but the premium they are paying is same.

Anonymous
Not applicable
Author

I will surely do it.

Anil_Babu_Samineni

Might be spell is wrong, Try this DISTINCT instead of Disitnct

1. Annual Loss Amount - (Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>} DISTINCT Annual_Loss)

2. Loss Amount Ratio - (Sum(DISTINCT Annual_Loss) + Sum(DISTINCT Risk_Loss) + Sum(DISTINCT Settlement_Cost)) / Sum(DISTINCT Premium_Amount)

3. Insurance Premium - Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>} DISTINCT Policy_Premium)

4. Premium Ratio - Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>}DISTINCT Policy_Premium) /Sum({<Year_Quarter = {"$(=Max(Year_Quarter))"}>}DISTINCT Premium_Amount)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

Do you want it to be done in script .

Anonymous
Not applicable
Author

Looks like you are aggregating things at the Year_Quarter level and this could certainly be done in the script using group by.

I am just finishing off redesigning a dashboard that displays many things at a month aggregation level.

The original had about 50 million data rows and the front end was stuffed full of horrendous expressions [albeit very cunning some of them]  and its performance was bad, plus it chewed up loads of RAM & CPU.

My new version has about 70 thousand rows and the front end only has simple expressions.  It is now lightening fast and consumes negligible RAM & CPU.  [Both cost money and CPU cycles consume electricity, making heat that needs air con cooling that takes more power that all contributes to global warming as well reducing the business's profit]

My personal general rules of thumb are :

  • If it can be done in the script then do it in the script
  • If your front end is full of over complex expressions then the data model is in need of improvement

One does need to think about what level of granularity is needed in the front end:

  • If you need to drill down to transaction level then you need to load your data at the transaction level so aggregation to a higher level would not be appropriate
  • But in my scenario the lowest level of front end drill down needed was month, so it was a perfect candidate for month level aggregation in the script
  • I also had a few other dimension to consider, such as Business Unit, Customer, Type, Function - So the group by was actually on these dimensions as well as month

But not knowing the details of your data model & needs I cannot make any definitive suggestions for your specific scenario.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

That means that you can never sum Amounts or Costs per region for example? That's a very weird data model. Why do you repeat all those amounts? The Distinct keyword by itself will slow down your document for no reason at all.

Anonymous
Not applicable
Author

yes it is DISTINCT only..QV takes it automatically when typed