Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

understand nested if

if(isnull(ScannedSales), if(isnull(EnteredSales), 0, EnteredSales), if(isnull(EnteredSales), ScannedSales, if(EnteredSales > ScannedSales, EnteredSales, ScannedSales))) as RealSales,

Can someone please break above statement and explain how it works and what it does. thanks

3 Replies
m_woolf
Master II
Master II

Maybe it will help you to see the code with indents:

if(isnull(ScannedSales),

    if(isnull(EnteredSales),

        0,

        EnteredSales),

    if(isnull(EnteredSales),

        ScannedSales,

            if(EnteredSales > ScannedSales,

                EnteredSales,

                ScannedSales

              )

       )

   ) as RealSales,

MK_QSL
MVP
MVP

if(isnull(ScannedSales),                                             //Your First IF Start

if(isnull(EnteredSales), 0, EnteredSales),      // First IF TRUE

if(isnull(EnteredSales),                                   // First IF False (2nd IF Start)

ScannedSales,                                    // 2nd IF TRUE

if(EnteredSales > ScannedSales, EnteredSales, ScannedSales))) // 2nd IF False with 3rd IF TRUE and FALSE)

its_anandrjs
Champion III
Champion III

This will

if(isnull(ScannedSales), //If this expression true then below line checks expression for null()


if(isnull(EnteredSales), 0, EnteredSales),  //For True if condition part

if(isnull(EnteredSales),    ScannedSales,  //For False if condition part

if(EnteredSales > ScannedSales, EnteredSales, ScannedSales) //Second nested if condition with true and false fields

   ) //Second If end here

   ) //First If end here

as RealSales,

Regards,

Anand