Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

IF statement in Script

I am currently doing the following as a Dimension in a chart, how Do I get this into a script?

Transactions is one table, ABICode is another table

=if(Transactions.ProductID = '33', Num(ABICode.ABIVixaInsuranceGroup),

if(Transactions.ProductID = '31', Num(ABICode.ABIBikeInsuranceGroup),Num(ABICode.ABIAxaInsuranceGroup)))

So in the script I would want to say something like - but i'm not sure where to put into the script.

if(Transactions.ProductID = '33', Num(ABICode.ABIVixaInsuranceGroup),

if(Transactions.ProductID = '31', Num(ABICode.ABIBikeInsuranceGroup),Num(ABICode.ABIAxaInsuranceGroup))) AS NewAbiInsurance Group

13 Replies
Not applicable
Author

Try something like this:

Data:

Load *,

        if(ProductID = '33', ABIVixaInsuranceGroup,

               if(ProductID = '31', ABIBikeInsuranceGroup,

                     ABIAxaInsuranceGroup

          )) as NewAbiInsuranceGroup;

Load ProductID,

        Num(ABIVixaInsuranceGroup) as ABIVixaInsuranceGroup,

        Num(ABIBikeInsuranceGroup) as ABIBikeInsuranceGroup,

        Num(ABIAxaInsuranceGroup) as ABIAxaInsuranceGroup,

        Field2,

        Field3;

SQL Select ProductID,

                  ABIVixaInsuranceGroup,

                  ABIBikeInsuranceGroup,

                  ABIAxaInsuranceGroup,

                  Field2,

                  Field3

From Table1;

Not applicable
Author

Am I suppossed to change the name Table1? as this produces an error when I add to script.

Kev.

Not applicable
Author

Yes, you must use the correct SQL sentence, i.e., field names, table names, etc.

Not applicable
Author

These are tables created in Qlikview not SQL.

Not applicable
Author

In this case:

Data:

Load *,

        if(ProductID = '33', ABIVixaInsuranceGroup,

               if(ProductID = '31', ABIBikeInsuranceGroup,

                     ABIAxaInsuranceGroup

          )) as NewAbiInsuranceGroup;

Load ProductID,

        Num(ABIVixaInsuranceGroup) as ABIVixaInsuranceGroup,

        Num(ABIBikeInsuranceGroup) as ABIBikeInsuranceGroup,

        Num(ABIAxaInsuranceGroup) as ABIAxaInsuranceGroup,

        Field2,

        Field3

Resident QVTable1;

Not applicable
Author

Thanks for your help Enrique, I now get the message -

Field not found - <ProductID>

Load ProductID,

        Num(ABIVixaInsuranceGroup) as ABIVixaInsuranceGroup,

        Num(ABIBikeInsuranceGroup) as ABIBikeInsuranceGroup,

        Num(ABIAxaInsuranceGroup) as ABIAxaInsuranceGroup

Anonymous
Not applicable
Author

Try:

Data:

Load *,

        if(Transactions.ProductID = '33', ABIVixaInsuranceGroup,

               if(Transactions.ProductID = '31', ABIBikeInsuranceGroup,

                     ABIAxaInsuranceGroup

          )) as NewAbiInsuranceGroup;

Load Transactions.ProductID,

        Num(ABIVixaInsuranceGroup) as ABIVixaInsuranceGroup,

        Num(ABIBikeInsuranceGroup) as ABIBikeInsuranceGroup,

        Num(ABIAxaInsuranceGroup) as ABIAxaInsuranceGroup,

        Field2,

        Field3

Resident QVTable1;

Not applicable
Author

I am obviously not doing something right,

If I use Resident Transactions;

It finds Transactions.ProductID as this exists in Transactions Table but then fails on ABIVixaInsuranceGroup

If I use Resident ABICode I get this -

Field not found - <Transactions.ProductID>

Load Transactions.ProductID,

        Num(ABIVixaInsuranceGroup) as ABIVixaInsuranceGroup,

        Num(ABIBikeInsuranceGroup) as ABIBikeInsuranceGroup,

        Num(ABIAxaInsuranceGroup) as ABIAxaInsuranceGroup,

        Field2,

        Field3

Resident ABICode

Not applicable
Author

¿The primary key of ABICode table is ProductID?