Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

csmqlik01
New Contributor II

Nested If with getfieldselections not working

Hi,

I'm trying to use getfieldselections in an expression,  to get the user's selection of the company code.

Because I have multiple possibilities, I use a nested if. But it works for only for one nested if, when I add another 'if' I get a error in the expression.  is there a restriction in use, because separate the syntax is working.

=if(GetFieldSelections([Company Code])= ' ',Sum({$<[Customer Code]=E({1<[NoFilter]={'Intercompany-4'}>})>}Quantity)

,if(GetFieldSelections([Company Code],'+',2)='BE04','US12',Sum({$<[Customer Code]=E({1<[Filter BE04/US12]={'Intercompany-4'}>})>}Quantity))

,if(GetFieldSelections([Company Code],'+',2)='BE04','US29',Sum({$<[Customer Code]=E({1<[Filter BE04/US29]={'Intercompany-4'}>})>}Quantity))

,if(GetFieldSelections([Company Code],'+',2)='US12','US29',Sum({$<[Customer Code]=E({1<[Filter US12/US29]={'Intercompany-4'}>})>}Quantity)))

or

=if(GetFieldSelections([Company Code],',',2)='BE04','US12',Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity)

,if(GetFieldSelections([Company Code],',',2)='BE04','US29',Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))

With both I get an error, can anyone say what the problem is

Or is it better to use pick match ..;  but how is the syntax to get the same result

Br

1 Solution

Accepted Solutions

Re: Nested If with getfieldselections not working

Super... Please close this thread by marking correct and helpful responses

Qlik Community Tip: Marking Replies as Correct or Helpful

Best,

Sunny

18 Replies
shraddha_g
Honored Contributor III

Re: Nested If with getfieldselections not working

Try

if(wildmatch(GetFieldSelections([Company Code],',',2),'BE04','US12'),Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity),

if(wildmatch(GetFieldSelections([Company Code],',',2),'BE04','US29'),Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))

csmqlik01
New Contributor II

Re: Nested If with getfieldselections not working

Hi,

Thanks for the quick answer, but still an error in the expression

=if(WildMatch(GetFieldSelections([Company Code],',',2)='BE04','US12',Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity))

,if(WildMatch(GetFieldSelections([Company Code],',',2)='BE04','US29',Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))))

Br

agigliotti
Honored Contributor II

Re: Nested If with getfieldselections not working

you should provide a sample qvf to show what you are looking for...

shraddha_g
Honored Contributor III

Re: Nested If with getfieldselections not working

Try,

if(wildmatch(GetFieldSelections([Company Code]),'BE04','US12'),Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity),

if(wildmatch(GetFieldSelections([Company Code],'BE04','US29'),Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))

csmqlik01
New Contributor II

Re: Nested If with getfieldselections not working

Hi,

Same result error

@Andrea  provide a qvf is difficult, sensitive data, I have to create a small qvf with sample data.  But I get a syntax error in the expression so I'm not that far to get a result in my Pivot table

Br

Re: Nested If with getfieldselections not working

If statement goes like this

If(Something = Something, True,

    If(Something2 = Something2, True, False)

Now, I am not sure your if statement is doing that

=if(GetFieldSelections([Company Code],',',2)='BE04','US12',Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity)

,if(GetFieldSelections([Company Code],',',2)='BE04','US29',Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))

Now what I am not sure is what is US12? Are you checking for 2 things BE04 and US12? If that is what you want, then may be this

=if(GetFieldSelections([Company Code],',',2)='BE04, US12', Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity), if(GetFieldSelections([Company Code],',',2)='BE04, US29', Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))

csmqlik01
New Contributor II

Re: Nested If with getfieldselections not working

Hi Sunny,

indeed I'm checking for BE04 and US12, so maybe I have to put it between ()

=if(GetFieldSelections([Company Code],'+',2)=('BE04',US12')...

And when I understand it, the last if, has to include a false statement, so could be " sum(Quantity) " if I have that requirement,

if(GetFieldSelections([Company Code]),('BE04','US12'),Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity),

if(GetFieldSelections([Company Code],('BE04','US29'),Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity, Sum(Quantity)))))

but it still gives an error

Br

Re: Nested If with getfieldselections not working

Did you check this?

=If(GetFieldSelections([Company Code], ',', 2) = 'BE04, US12', Sum({$<[Filter BE04/US12]=-{'Intercompany-4'}>}Quantity), If(GetFieldSelections([Company Code], ',', 2) = 'BE04, US29', Sum({$<[Filter BE04/US29]=-{'Intercompany-4'}>}Quantity))

Re: Nested If with getfieldselections not working

Also, the last if doesn't need to include a false statement.... you can actual leave it blank....

Community Browser