Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi guys,
I have a problem with a straight table that shows zeros instead of calculating the desired measure. I am rocking the following data model (test sample):
Data:
LOAD * INLINE [
Code,Document,Order,Date
A100,1111,O100,10.05.2016
A200,1111,O200,15.05.2017];
Documents:
LOAD * INLINE [
Document,Validity_Start,Validity_End,Value_Planned,Value_Actual
1111,01.01.2015,31.12.2019,100000,150000];
Divisions:
LOAD * INLINE [
Code,Division
A100,South];
Let me explain the data:
So everything is cool until I put this into a table. Then if there is a document that has more than one order and a missing division, the measures show zero:
This can be avoided by including Order as an additional dimension:
However, I do not want to do this as in the real dataset one document might have hundreds of orders booked against it on the same date and the table becomes huge. Therefore, the level of detail that I need is as shown in the first table.
The best solution I have come up with is to use Aggr() like this:
This solves my problem but kind of slows down the app, which I do not like...
So, two questions:
Thank you!
To avoid letting the Division mess up your Sums you can simply use the expressions:
Sum(TOTAL <Document> Value_Planned)
Sum(TOTAL <Document> Value_Actual)
These sums are independent of Division and should not take this dimension into consideration.
Hey Mike
I think there is no point in showing the second record as it doesn't have a division associated, its like a full outer join
but if the business asks then we have to show it ...
if you really want you can suppress the second record so that it doesn't come up, as you said in real situation you might be ended up showing multiple records which may not be give any value to the business
To avoid letting the Division mess up your Sums you can simply use the expressions:
Sum(TOTAL <Document> Value_Planned)
Sum(TOTAL <Document> Value_Actual)
These sums are independent of Division and should not take this dimension into consideration.
or even simpler - you could left join in the Division names to the Data table like this:
LEFT JOIN (Data)
LOAD * INLINE [
Code,Division
A100,South];
Then you could keep your simple Sum(Value_Planned) and Sum(Valule_Actual) and get the two rows you need.
The problem is really in the Divisions table which is inconsistent with the Data (orders) table. So you should either cleanse and fix the Divisions table during the load script phase by adding the Code for the divisions that doesn't exist in the Data (orders) table. This follows normal Business Intelligence and Data Warehouse best practices - which says that you shouldn't have dimension keys in a fact table that hasn't corresponding keys in the dimension table.
Since I mentioned cleansing the dimension Divisions - here is the load script that could be used to create the missing Code keys:
Divisions:
LOAD *,Code AS Code_ INLINE [
Code,Division
A100,South];
// Make sure to append unknown division codes to the dimension table Divisions:
CONCATENATE LOAD
Code,
'(' & Code & ' unknown)' AS Division
RESIDENT
Data
WHERE
Not( Exists( Code_ , Code ) ) ;
DROP FIELD Code_;
This is how it will look like:
Notice the (A200 unknown) in the Division column....
Hi Petter!
Thanks a lot! Sum(Total <Document> Value) did the trick. It provides the same result as my Aggr() solution but is much faster and does not slow down the app! Exactly what i needed! Btw. I never used this syntax, is it something like set analysis? Could you please tell me how is it called or where I could read more about it?
Also thank you for explaining the reason why my table did not work. So when a dimensional value is missing Qlik will not calculate the measures as I would expect it to. I will not change the script of this particular app, but what you posted as suggestion is very interesting and I would use it in future.
Thank you again!
For the syntax and the documentation of TOTAL <field1,field2....> in any aggregate function you can have a look at what is written about Sum() :