Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

General QLikeView Advice and ETL / Expression Question

Hi There

I am doing a project where there are basic facts but a lot of business rules must be applied to the data.

I am new to QLikView and this i smy first project so please understand these may be stupid questions.

I have done all the tutorials and ELlearning etc, howevre they do not cover expressions and scripting in much detail and i cannot find more advacned resources on these (one day i will have time to study the reference manaul :))

First question:

In general is it better to do the business rules and formulas and all the data manipulation upfront say in the database and use that data into QLikview. Or use scripting / expressions for this.

I am been advised to use QLikView powerful scripting etc and not to use complex sql statements for loading data, however being new to QLikView i am finding it very difficult to get used to the scripting. So is it OK to do all of this upfront and not in QLikView?

Lastly some general expression help:

If i have a fact row as below:

TimeKey Measure DateValue1 DateValue2 DateValue3

20090112 100.12 2009/03/01 2009/02/13 2008/12/09

In QLikView i need to build expression with business rules as mentioned above.

The rule is that if various combinations of the DateValues 1-3 are filled the Measure value must be added or subtracted, how do i do that?

I hate to waste your guys time with trivial questions, so if you could point me in the right directions to expressions that apply business rules that would be great.

Does the QlikView cookbook have this information ?

The expression examples i have found are more around Year to Year and variance expressions, not logical rules based on other fact attributes.

OR as mentioned above is it a better practice to do this upfront in the database and then bring that data into QLiview ???

Thanx for the help

1 Solution

Accepted Solutions
johnw
Champion III
Champion III


Sean wrote:In general is it better to do the business rules and formulas and all the data manipulation upfront say in the database and use that data into QLikview. Or use scripting / expressions for this.

My personal opinion is that BUSINESS rules should be applied within the business system, which is to say they should be applied before loading into QlikView, which is the REPORTING system. However, if the rules are actually just REPORTING rules, then I would apply them within QlikView rather than within your business system.

An an example, let's say we're doing a cost system. At a basic level, we have business facts - I paid $100 each for this part, I had to scrap 30 items due to this problem on this machine. On top of that, we have business rules for how the costs are calculated - the cost of scrapped items should be allocated across all of the same type of items produced in the month, fixed costs should be allocated by the time spent on some particular machine, this type of part should use a 12 month rolling average of the price paid rather than the actual price paid. And finally, we have reporting rules for how the costs are to be displayed - group all part costs into a single category because the users don't care about the details, use the date shipped rather than other dates like the date ordered or date finished, allow users to select whether or not to include the cost of scrapped items.

The categories are pretty nebulous, as may be evident in the example. Saying for certain whether a piece of information is a fact, a business rule or a reporting rule may be difficult. But to the extent you can split them into these categories, that's what I like to do.

Most systems I've built don't have much complexity in the reporting rules, to the point where you could hardly call them rules at all. I believe only one system I've built has had complicated reporting rules. While I COULD have staged the data for QlikView in the business system by executing the reporting rules on that side, it seemed like a cleaner separation to me to execute them in the QlikView script itself. As a result, that particular script is long and complicated, and I believe takes over an hour to load. The speed could certainly be improved with some performance tuning; I've learned a lot about script performance since then, but it hasn't been worth revisiting since it only loads once per day.

Still, there's nothing strictly wrong with staging the data for QlikView by executing the reporting rules within your business system. If you find that to be more convenient for you, I don't see that it would cause any problems.

As far as doing the formulas in the expressions, from a performance standpoint, it is best to keep that to a minimum. The more you can do in your business system or in the script, the faster the various charts will display for your users, and so the happier they'll be with it.

I am been advised to use QLikView powerful scripting etc and not to use complex sql statements for loading data, however being new to QLikView i am finding it very difficult to get used to the scripting. So is it OK to do all of this upfront and not in QLikView?

While I don't see anything specifically wrong with using complex SQL, if you're dealing with large volumes of data, I would recommend staging it in QVDs, and then having the applications load from the QVDs. Doing that, I've found that my SQL tends to be very simple, and all of the complicated joins are done in the QlikView script.

Lastly some general expression help:
If i have a fact row as below:
TimeKey Measure DateValue1 DateValue2 DateValue3
20090112 100.12 2009/03/01 2009/02/13 2008/12/09
In QLikView i need to build expression with business rules as mentioned above.
The rule is that if various combinations of the DateValues 1-3 are filled the Measure value must be added or subtracted, how do i do that?

If I understand what you're asking, something like this:

LOAD
...
,if(your date value conditions,+1,-1)*Measure as Measure
...

And then your expression would just be something like sum(Measure).

If there is a reason you CAN'T apply the rule in the script, and must apply it in the expression, something like this:

sum(if(your date value conditions,+1,-1)*Measure)

Does the QlikView cookbook have this information ?

It has a lot of examples, but I'm not sure if it specifically addresses where and how business and reporting rules are to be applied.

The expression examples i have found are more around Year to Year and variance expressions, not logical rules based on other fact attributes.
OR as mentioned above is it a better practice to do this upfront in the database and then bring that data into QLiview ???

From the sound of it, I'd classify this as a reporting rule rather than a business rule. If so, then I think the load script is the best place to apply the rule.

View solution in original post

5 Replies
johnw
Champion III
Champion III


Sean wrote:In general is it better to do the business rules and formulas and all the data manipulation upfront say in the database and use that data into QLikview. Or use scripting / expressions for this.

My personal opinion is that BUSINESS rules should be applied within the business system, which is to say they should be applied before loading into QlikView, which is the REPORTING system. However, if the rules are actually just REPORTING rules, then I would apply them within QlikView rather than within your business system.

An an example, let's say we're doing a cost system. At a basic level, we have business facts - I paid $100 each for this part, I had to scrap 30 items due to this problem on this machine. On top of that, we have business rules for how the costs are calculated - the cost of scrapped items should be allocated across all of the same type of items produced in the month, fixed costs should be allocated by the time spent on some particular machine, this type of part should use a 12 month rolling average of the price paid rather than the actual price paid. And finally, we have reporting rules for how the costs are to be displayed - group all part costs into a single category because the users don't care about the details, use the date shipped rather than other dates like the date ordered or date finished, allow users to select whether or not to include the cost of scrapped items.

The categories are pretty nebulous, as may be evident in the example. Saying for certain whether a piece of information is a fact, a business rule or a reporting rule may be difficult. But to the extent you can split them into these categories, that's what I like to do.

Most systems I've built don't have much complexity in the reporting rules, to the point where you could hardly call them rules at all. I believe only one system I've built has had complicated reporting rules. While I COULD have staged the data for QlikView in the business system by executing the reporting rules on that side, it seemed like a cleaner separation to me to execute them in the QlikView script itself. As a result, that particular script is long and complicated, and I believe takes over an hour to load. The speed could certainly be improved with some performance tuning; I've learned a lot about script performance since then, but it hasn't been worth revisiting since it only loads once per day.

Still, there's nothing strictly wrong with staging the data for QlikView by executing the reporting rules within your business system. If you find that to be more convenient for you, I don't see that it would cause any problems.

As far as doing the formulas in the expressions, from a performance standpoint, it is best to keep that to a minimum. The more you can do in your business system or in the script, the faster the various charts will display for your users, and so the happier they'll be with it.

I am been advised to use QLikView powerful scripting etc and not to use complex sql statements for loading data, however being new to QLikView i am finding it very difficult to get used to the scripting. So is it OK to do all of this upfront and not in QLikView?

While I don't see anything specifically wrong with using complex SQL, if you're dealing with large volumes of data, I would recommend staging it in QVDs, and then having the applications load from the QVDs. Doing that, I've found that my SQL tends to be very simple, and all of the complicated joins are done in the QlikView script.

Lastly some general expression help:
If i have a fact row as below:
TimeKey Measure DateValue1 DateValue2 DateValue3
20090112 100.12 2009/03/01 2009/02/13 2008/12/09
In QLikView i need to build expression with business rules as mentioned above.
The rule is that if various combinations of the DateValues 1-3 are filled the Measure value must be added or subtracted, how do i do that?

If I understand what you're asking, something like this:

LOAD
...
,if(your date value conditions,+1,-1)*Measure as Measure
...

And then your expression would just be something like sum(Measure).

If there is a reason you CAN'T apply the rule in the script, and must apply it in the expression, something like this:

sum(if(your date value conditions,+1,-1)*Measure)

Does the QlikView cookbook have this information ?

It has a lot of examples, but I'm not sure if it specifically addresses where and how business and reporting rules are to be applied.

The expression examples i have found are more around Year to Year and variance expressions, not logical rules based on other fact attributes.
OR as mentioned above is it a better practice to do this upfront in the database and then bring that data into QLiview ???

From the sound of it, I'd classify this as a reporting rule rather than a business rule. If so, then I think the load script is the best place to apply the rule.

Not applicable
Author

Hi John

Wow thank you so much for the detailed response , i really respect the advise given and it certainly helped significantly.

One last question, currently the only way i have to really start trying to learn how to do complicated scripting / expressions it by looking at examples and demo's i have downloaded, if you have a better source PLEASE SHARE 🙂

Otherwise i will just keep trying at it!

Thanx a million ! All my questions were answered well !

johnw
Champion III
Champion III

Well, there may or may not be better sources of information, but I learned scripting and expressions from:

  • examples and demos
  • using the Help function extensively
  • reading the forum
  • a whole lot of trial and error
Not applicable
Author

Hi John

🙂 yeah this sounds very familiar i am on that path as well. Just trying to wrap my head around QV scripting, from demo's and examples at the moment and trying to figure out if it is better to do the logic in the script or expression. etc etc

But you have helped greatly.

One last question, when you mentioned the folllowing

"While I don't see anything specifically wrong with using complex SQL, if you're dealing with large volumes of data, I would recommend staging it in QVDs, and then having the applications load from the QVDs. Doing that, I've found that my SQL tends to be very simple, and all of the complicated joins are done in the QlikView script."

Are you saying have Qlikview documents that are simply scripts that load the data and then have the main QLikview document "application" that just loads the data from them, am i understanding correctly ? If so why is it better to load from QVD'd that have complex sql when that could be in the script of the main docuemnt, seems like an additional step ? And do you have an example of a page reference number from the help or reference manaual that shows how to load data from another QVD?

Thank you again for the assistance !

johnw
Champion III
Champion III


Sean wrote:Are you saying have Qlikview documents that are simply scripts that load the data and then have the main QLikview document "application" that just loads the data from them, am i understanding correctly ? If so why is it better to load from QVD'd that have complex sql when that could be in the script of the main docuemnt, seems like an additional step ? And do you have an example of a page reference number from the help or reference manaual that shows how to load data from another QVD?

If you just have a single application, it would be a waste to load from your database into a QVD, then from the QVD into your application. The advantages come when you have a lot of different applications, all using the same data.

  • It is typically much faster to load from a QVD than from a database. So if you load once from the database, and many times from the QVD, your applications will load faster.
  • There will be less impact on your main business sytem if you load once from it rather than once per application.
  • If you change how data is sourced, you won't need to change your user applications, only the one application that writes the QVD.
  • In our specific case, we don't have 64-bit ODBC drivers for our database, but some applications are large enough to require reloading on a 64-bit server. These applications can therefore only load from QVDs. The QVDs themselves, being much simpler than the final applications, can still be built in a 32-bit environment.

There are probably other advantages as well.

As far as an example, let's say you were doing this in your user application:

[Order Items]:
LOAD
DEID as "Order Item"
,DECONS as "Customer"
,DECQTY as "Order Quantity"
,DEBPYR as "Bill Payer"
,ASCRST as "Credit Rating"
;
SQL SELECT
DEID
,DECONS
,DECQTY
,DEBPYR
,ASCRST
FROM SYSTLC.ATDE101R
, SYSTLC.ATAS101R
WHERE DETYP = 'PRIME'
AND DESTA = 'ACTV'
AND DECQTY > 20000
AND ASID = DEBPYR
AND ASCRST IN ('A','B')
FOR FETCH ONLY
;


The QVD approach would involve three applications instead of one. The first would load an order item QVD. It will be more general than our application, in this case loading the order items regardless of status or quantity, and also loading order item types other than prime.

[Order Items]:
LOAD
DEID as "Order Item"
,DECONS as "Customer"
,DECQTY as "Order Quantity"
,DEBPYR as "Bill Payer"
,DESTA as "Order Item Status"
,DETYP as "Order Item Type"
;
SQL SELECT
DEID
,DECONS
,DECQTY
,DEBPYR
,DESTA
,DETYP
FROM SYSTLC.ATDE101R
WHERE DETYP IN ('PRIME','NPSLS','FGSTK','GNLSTK')
FOR FETCH ONLY
;
STORE [Order Items] INTO Order_Item.qvd
;


The second would load bill payer information:

[Bill Payers]:
LOAD
ASID as "Bill Payer"
,ASCRST as "Credit Status"
;
SQL SELECT
ASID
,ASCRST
FROM SYSTLC.ATAS101R
WHERE ASTYP = 'CORP'
FOR FETCH ONLY
;
STORE [Bill Payers] INTO Bill_Payer.qvd
;


And finally, the application would load from the QVDs as efficiently as possible (efficiently in this case does not refer to the simplicity of the code, but rather the speed of the reload - this code could be simpler, but it would execute more slowly):

[Order Items]:
LOAD * INLINE [
Order Item Type, Order Item Status, Credit Status
PRIME,ACTV,A
PRIME,ACTV,B
];
INNER JOIN ([Order Items])
LOAD
"Bill Payer"
,"Credit Status"
FROM Bill_Payer.qvd (QVD)
WHERE EXISTS("Credit Status")
;
INNER JOIN ([Order Items])
LOAD
"Order Item"
,"Customer"
,"Order Quantity"
,"Bill Payer"
,"Order Item Status"
,"Order Item Type"
FROM Order_Item.qvd (QVD)
WHERE EXISTS("Order Item Status")
;
INNER JOIN ([Order Items])
LOAD "Order Item"
RESIDENT [Order Items]
WHERE "Order Quantity" > 20000
;
DROP FIELDS
"Order Item Type"
,"Order Item Status"
;