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: 
JACKNIEKERK
Creator
Creator

if then else statement systax

need to display in grid based on one the 2 valid

if (Pieces <> 0 , Pricetotal/Pieces) else (Grams <> 1  then Pricetotal/Grams)

Field names are ok formule gives error,  so what do I  wrong in syntax  ? 

2 Solutions

Accepted Solutions
Taoufiq_Zarra

also

if(Grams <> 0, sum(Pricetotal/Grams)),sum(Pricetotal/Pieces)) 

 

if not can you share a sample data and the expected output ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

JACKNIEKERK
Creator
Creator
Author

Hello  it works ok

just learned that i must be carefull  with capitals , will not generate error, just will give nothing 

This Grams  should be  grams    then it works

thanks for helping out

 

if(Grams <> 0, sum(Pricetotal/Grams)),sum(Pricetotal/Pieces))

View solution in original post

7 Replies
Taoufiq_Zarra

May be

=if(Pieces <>0,Pricetotal/Pieces,if(Grams <>1,Pricetotal/Grams))
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
JACKNIEKERK
Creator
Creator
Author

Ok what I realize is that grams goes first allways,  due sometimes in table it tells how many items in the total  weight

this runs ok  if(Grams <> 0, sum(Pricetotal/Grams))

But in case NO grams only pieces , how do i that behind  ,

 

in VB  I could work with something like

if(Grams <> 0, sum(Pricetotal/Grams)) else  sum(Pricetotal/Pieces)) 

Taoufiq_Zarra

also

if(Grams <> 0, sum(Pricetotal/Grams)),sum(Pricetotal/Pieces)) 

 

if not can you share a sample data and the expected output ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
JACKNIEKERK
Creator
Creator
Author

Hello , its simple i think ,

Grams is first choice, due to it could happen field Grams contains value And Pieces contains value
if Grams =0 then Pieces are counting

I my visual programs i have this
just do not know ,  and trying to find the syntax in Qlikview

If Grams <> 0 Then
  Sum = Pricetotal / Grams
    Else
 Sum = Pricetotal / Pieces
End If

 

JACKNIEKERK
Creator
Creator
Author

Hello  it works ok

just learned that i must be carefull  with capitals , will not generate error, just will give nothing 

This Grams  should be  grams    then it works

thanks for helping out

 

if(Grams <> 0, sum(Pricetotal/Grams)),sum(Pricetotal/Pieces))

Saravanan_Desingh

You can also add Null check to this, if you want.

if(Grams <> 0 And Not IsNull(Grams), sum(Pricetotal/Grams)),sum(Pricetotal/Pieces))

 

JACKNIEKERK
Creator
Creator
Author

thanks for tip