Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
evansabres
Specialist
Specialist

Nested IF Statement with multiple conditions

I am attempting to create a nested if statement with several conditions. Below is how I have the expression formatted currently, however I am getting an error or 'IF takes 2-3 parameters,' which I believed I had

=if(mtrc_videoviews < 300 and brandID = 1, mtrc_impressions * 0.00936, mtrc_impressions * 0.00806, if(mtrc_videoviews < 300 and brandID = 2, mtrc_impressions * 0.00996, mtrc_impressions * 0.00762))

How can I correct

1 Solution

Accepted Solutions
ms_12
Partner - Contributor III
Partner - Contributor III

You cannot write two else part in if statement. so structure your if something like below

if(mtrc_videoviews < 300 and brandID = 1, mtrc_impressions * 0.00936, 

if(<condition> , mtrc_impressions * 0.00806,

 if(mtrc_videoviews < 300 and brandID = 2,

mtrc_impressions * 0.00996, mtrc_impressions * 0.00762)))

View solution in original post

5 Replies
ms_12
Partner - Contributor III
Partner - Contributor III

You need to write if condition for highlighted part.

if(mtrc_videoviews < 300 and brandID = 1,
mtrc_impressions * 0.00936, mtrc_impressions * 0.00806,
if(mtrc_videoviews < 300 and brandID = 2, mtrc_impressions * 0.00996, mtrc_impressions * 0.00762))

rrsrini2907
Creator
Creator

Is this what you are expecting?

=if(mtrc_videoviews < 300 and brandID = 1, mtrc_impressions * 0.00936,
if(mtrc_videoviews < 300 and brandID = 2, mtrc_impressions * 0.00996,
if(mtrc_videoviews >= 300 and brandID = 1, mtrc_impressions * 0.00806,
if(mtrc_videoviews >= 300 and brandID = 2, mtrc_impressions * 0.00762))))

So BrandID = 1 has two logic's based on video views similarly for BrandID = 2.

marcos_herrera
Partner - Creator III
Partner - Creator III

Hi Dear Evansabres

The highlighted part on Kush_qlik post is the wrong part of your script, you can try with the following sentence

 

=if(mtrc_videoviews < 300 and brandID = 1,
mtrc_impressions * 0.00936,
if(mtrc_videoviews < 300 and brandID = 2,
mtrc_impressions * 0.00996,
mtrc_impressions * 0.00762))

 

evansabres
Specialist
Specialist
Author

The format of this expression works, however I need to incorporate the highlighted portion of what I have below:

=if(mtrc_videoviews < 300 and brandID = 1, mtrc_impressions * 0.00936, mtrc_impressions * 0.00806, if(mtrc_videoviews < 300 and brandID = 2, mtrc_impressions * 0.00996, mtrc_impressions * 0.00762))

ms_12
Partner - Contributor III
Partner - Contributor III

You cannot write two else part in if statement. so structure your if something like below

if(mtrc_videoviews < 300 and brandID = 1, mtrc_impressions * 0.00936, 

if(<condition> , mtrc_impressions * 0.00806,

 if(mtrc_videoviews < 300 and brandID = 2,

mtrc_impressions * 0.00996, mtrc_impressions * 0.00762)))