Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

nilsgc
New Contributor III

If and Sum - different results

Hi,

Why do these 2 expressions give different results?     Currency is in a separate table and not associated with other tables.

 

1:

sum({<Year=,Quarter=,Month=>} if(Currency = ‘Local’, [Local Amount], [Group Amount]))

 

2:

if(Currency = ‘Local’,

    sum({<Year=,Quarter=,Month=>} [Local Amount])

    sum({<Year=,Quarter=,Month=>} [Group Amount]))

The first expression gives the correct result - but I like the second expression the best

Regards

Nils

Tags (2)
2 Replies
MVP
MVP

Re: If and Sum - different results

I think you need to use Sum().  Try below expression.

=Sum(if(Currency = ‘Local’,

    sum({<Year=,Quarter=,Month=>} [Local Amount])

    sum({<Year=,Quarter=,Month=>} [Group Amount])))

Regards,

Jagan.


jonbrough
Valued Contributor

Re: If and Sum - different results

My understanding is that when you use sum(if(.... your test and calculation is being run once for each datapoint. However, if you use if(sum(... then you are summing all the datapoints first, and then testing the result. This isn't what is usually required, as in this case where the currency is relevant to each Amount.

I agree that if..sum feels more logical, but after a while sum .. if doesn't seems quite natural too.

Jonathan

Community Browser