Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

problem using set analysis with IF statement

Hi community!

I have an IF statement (that works) as follows:

=IF(Sum (Schedule) >0), Sum(Schedule) - Sum(Amount), 0)

when I introduce set analysis into this IF statement, it doesn't work anymore.

for example:

=IF(Sum ( {$<SiteName = {Rochester} Schedule) >0), Sum( {$<SiteName = {Rochester} Schedule) - Sum( {$<SiteName = {Rochester} Amount), 0)

One thing to note is that the SiteName is from a Load Inline statement like below.  I don't know if this is causing any of my issues however.

SiteLoc:

LOAD * INLINE [
    SiteName, Site, BrandType
    Rochester, 4005, MHL
    Rochester, 4045, MHL
    Rochester, 4043, MHL
    Rochester, 4305, USB
    Rochester, 4345, USB
    Rochester, 4343, USB
    Wisconsin, 4007, MHL
    Wisconsin, 4055, MHL
    Wisconsin, 4307, USB
    Wisconsin, 4355, USB
];

Does anybody know why i'm having these issues?

5 Replies
Not applicable
Author

Hi! Not sure that it's the whole solution but there are syntax errors. Try:

=IF(Sum ( {$<SiteName = {Rochester}>} Schedule) >0), Sum( {$<SiteName = {Rochester}>} Schedule) - Sum( {$<SiteName = {Rochester}>} Amount), 0)

Not applicable
Author

Hi Thomas,

Sorry about my bad syntax, but the syntax is not the issue.  Your solution/syntax is correct, but it just won't work in my document for some reason.

erichshiino
Partner - Master
Partner - Master

Can you also post a load inline with Schedule, amount and the key to the sitename table?

brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi,

the expression is still wrong:

=IF(Sum ( {$<SiteName = {Rochester}>} Schedule) >0, Sum( {$<SiteName = {Rochester}>} Schedule) - Sum( {$<SiteName = {Rochester}>} Amount), 0)

Not applicable
Author

Hi,

Try this:

=IF(Sum ({$<SiteName = {"Rochester"} >} Schedule)>0,

Sum({$<SiteName = {"Rochester"} >} Schedule) - Sum( {$ <SiteName= {"Rochester"} >} Amount),

0)


If above will not work, it must be something with your data.

Regards,

Janusz