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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

sum with nested if

Hi ,

I have below script in my expression

when i have one row code like ;

Sum(if(((TotalCode=86 AND PortID=1153) or (TotalCode=88 AND PortID=1153) or (TotalCode=87 AND PortID=1153)) ,Bedehkar-Bestankar)/1000000) 

it's work fine But

when i have 2 row code like ;

Sum(if(((TotalCode=86 AND PortID=1153) or (TotalCode=88 AND PortID=1153) or (TotalCode=87 AND PortID=1153)), 
if(((TotalCode=86 AND PortID=3304) or (TotalCode=88 AND PortID=3304) or (TotalCode=87 AND PortID=3304)),Bedehkar-Bestankar)/1000000))

it's not work and receive me 0.

i want my script work with multi row code .

can anyone help me

regards

hamide

Labels (1)
5 Replies
sunny_talwar
MVP
MVP

Can you share an example? It is hard to understand what your requirement is just by looking at the code

roger_stone
Creator III
Creator III

The second IF is tested if the first IF is true. I think you need to review your logic.

marcus_sommer
MVP
MVP

Try something like this:

Sum(match(TotalCode, 86,87,88) AND match(PortID, 1153,3304),[Bedehkar-Bestankar])/1000000))

- Marcus

Mark_Little
Luminary
Luminary

HI,

Yer more details would be helpful. even if you explain what you want in English?

It seems at the moment you are saying

If statement 1 is true,

     Check that statement 2 is also true, then sum.

From look at that the logic it would be zero as your first statement returns values matching

(TotalCode=86 AND PortID=1153) or (TotalCode=88 AND PortID=1153) or (TotalCode=87 AND PortID=1153)

So they can't then also match

(TotalCode=86 AND PortID=3304) or (TotalCode=88 AND PortID=3304) or (TotalCode=87 AND PortID=3304)

Maybe something like

Sum(if((TotalCode=86 AND PortID=1153) or (TotalCode=88 AND PortID=1153) or (TotalCode=87 AND PortID=1153), 

      Bedehkar-Bestankar/1000000,

  if((TotalCode=86 AND PortID=3304) or (TotalCode=88 AND PortID=3304) or (TotalCode=87 AND PortID=3304),

  Bedehkar-Bestankar)/1000000))

Or

     Sum(if((TotalCode=86 AND PortID=1153) or (TotalCode=88 AND PortID=1153) or (TotalCode=87 AND PortID=1153) or (TotalCode=86 AND PortID=3304) or (TotalCode=88 AND PortID=3304) or (TotalCode=87 AND PortID=3304),

  Bedehkar-Bestankar/1000000)

buzzy996
Master II
Master II

ur 2'nd if condition is wrong,

use Marcus_Sommer suggestion,tht helps.