Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
Contributor III

Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

I have a dimension like day and for every day a factor with a fixed value for the day.

I want to sum a measure for different products multiplied by factor of each day. So I'll get a weighted sum.

I mounted a chart of type table with dimension day and factor and two expressions:

expA : sum(measure * factor)

expB : sum(measure) * factor

mathematically thinking both values should give the same result, but it doesn't happen.

Why ?

dayfactorsum(measure)sum(measure)*factorsum(measure*factor)
552276552
01oct20120.5552276552

the expected answer is 276

Tags (2)
7 Replies
Highlighted
MVP
MVP

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

I can't reproduce your issue.

The answer to your issue is probably depending on your data model or the data itself.

Could you upload a small sample application that demonstrates your issue?

Highlighted
Partner
Partner

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

Without a bit more data I cannot be sure.  But the difference would be that is Sums all the measures and then multiplies is by the factor in the Sum(Measure)*factor example.  In the Sum(Measure*Factor) example it will multiply each individual line by the associated factor and then sum each lines result. 

Highlighted
Contributor III
Contributor III

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

neither can I with a simplified sample data. As The orignal data is too complex to load into an example, i cannot attach it here.

Anyway, thanks John Witherspoon i got a solution, through sum(aggr(sum(measure),day) * factor) , even for my strange data.

As i understood aggr(sum(measure),day) sums, for each day, the value of measure and then multiplies by factor, and the overall total becomes the sum of the sums for all rows. and that is what i wanted.

Highlighted
MVP
MVP

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

Yes,

this might give you the result you expect.

But I would still strongly suggest that you try to understand why you see this behaviour, today or in the near future.

The risk is quite high that you (or the next developer editing your document) run into similar problems or even more tricky ones.

Regards,

Stefan

MVP & Luminary
MVP & Luminary

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

Maybe it's related to some NULL values ...

Vizlib Head of R&D
Highlighted
MVP
MVP

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

Yes, I also thought about NULLs, but wouldn't we suspect sum(measure*factor) to be smaller than sum(measure)*factor then?

Highlighted
MVP & Luminary
MVP & Luminary

Re: Do not get the difference between sum(measure)*Dim vs sum(measure*Dim)

Either measure or factor could be null (or negative)...

Vizlib Head of R&D