Discussion Board for collaboration on QlikView Scripting.
I have source data which has multiple lines for the one primary key.
It goes like this
Property Reference | SOR Code | Work Programme Bk | Location | Total Cost
1 kit01 LCQ kitchen 100
1 kit03 LCQ kitchen 120
1 kit04 PR3 kitchen 140
1 pgi01 LCQ bedroom 95
1 pgi03 LCQ bedroom 150
1 plu40 SOW bath 400
2 kit50 LCQ kitchen 200
2 plu05 LCQ bath 400
2 ele30 LCQ WC 350
2 min95 RSW HALL 40
what i'm trying to do now is figure out the sum of the total cost of all LCQ items for anything starting with 'kit'
the following is what I have written so far, but the sum works out to be something completely different.
I would really appreciate a little guidance
SUM(IF(([Total Cost] > 0) AND ([SOR Code] like 'KIT*) AND ([Work Programme Bk] like 'LCQ'), [Total Cost], 0] as KIT_Total_LCQ_Cost
Group by [Property Reference] and [Work Programme Bk] and [SOR Code];
When I run this function I keep getting that its an "invalid expression"
Could someone shed a bit of light on where I might be wrong?
Solved! Go to Solution.
I mentioned in my other thread that I actually found that the join done at the end of the EDW table was what was causing the problem.
thanks for all your assistance guys!
what I also forgot to mention is the fact that when I remove the last 2 fields in the group by line, and just say
group by [Property Reference] ;
this is where I get a totally different sum to what I expected.
If you want to group your sum by Property Reference, try
SUM( [Total Cost] ) as KIT_Total_LCQ_Cost
WHERE [Work Programme Bk] = 'LCQ' AND [SOR Code] LIKE 'kit*' AND [Total Cost] > 0
Group by [Property Reference];
Unfortunately this still doesn't work.
so instead of showing me for example 220 for kitchen lcq items for property 1 I'm getting some massive number such as 230,000.
why could this be?
Use below expressions
SUM(IF(([Total Cost] > 0) AND (WildMatch([SOR Code], 'kit*') AND (Upper([Work Programme Bk]) = 'LCQ'), [Total Cost], 0] as KIT_Total_LCQ_Cost
Group by [Property Reference], [Work Programme Bk] , [SOR Code];
OR just load the required values by using where conditions
SUM([Total Cost] ) as KIT_Total_LCQ_Cost
WHERE [Total Cost] > 0 AND WildMatch([SOR Code], 'kit*') AND Upper([Work Programme Bk]) = 'LCQ'
Group by [Property Reference];
Hope this helps you.
so it turns out the script is still giving me the wrong information again
its giving me completely different values... and I thought it was related to fixing up the logic but apparently not.
i'm sure its related to the load... but I don't know how to fix this..
It's hard to help with the information provided.
You can create a similar straight table with property reference as dimension and sum([Total Cost]) as expression in the frontend, then filter the other fields by selecting in the list boxes. Do you see the same numbers as shown in the aggregated table in the data model?
Or why do you think the numbers are off?
well the problem is that I need to hard code this to be use this information for another function...
so in other words i'm trying to figure out whether money has been spent on certain lcq items with condition data coming from another table.