Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
capriconuser
Creator
Creator

decode in qliksense

hi 

how i use decode in qliksense .. this is the expression 

SUM(DECODE(Rcount,0,DECODE(H.documentno,NULL,(C.gross- C.amont),0),0))

how to use decode in qliksense ?

 

any help 

Labels (2)
17 Replies
capriconuser
Creator
Creator
Author

i want tio use this in chart expression not in script

is this possible to combine both statement and remove plus sign  in expression 

sum({<[Year] = {"$(=vYear)"},[Rcount ] = {0},[Table1.Flag] = {'USA'},[Table2.Flag] = {'USA'}, documentno={"*"} >} (gross - amount))
+
sum({<[Year] = {"$(=vYear)"},[Rcount ] -= {0},[Table1.Flag] = {'USA'},[Table2.Flag] = {'USA'}>} (gross - amount))

is there  any logic @JuanGerardo 

JuanGerardo
Partner - Specialist
Partner - Specialist

Yes, you can use intersection and union of both data sets:

sum({
<[Year] = {"$(=vYear)"},[Table1.Flag] = {'USA'},[Table2.Flag] = {'USA'}>
*
(<[Rcount ] = {0}, documentno={"*"} > + <[Rcount ] -= {0}>)
} (gross - amount))

 

JG

capriconuser
Creator
Creator
Author

why u use gross-amount 1 time .. whereas in SQL expression this is being used twice.. will u please explain code 

 

and also this expression shows an error .. error : error is in set modifier expression

I am trying this but I think this does not meet this condition 

 

SUM(DECODE(Rcount,0,DECODE(documentno,NULL,0,(gross - amount)),(gross - amount)))
 sum({<[Year] = {"$(=vYear)"},
 [Rcount ] = {">0"},[Table1.Flag] = {'USA'},
 [table2.Flag]  = {'USA'} >}
 if([Rcount ] = 0,
 if(isNull([documentno]),0,
([GROSS]- [AMOUNT])),
([GROSS]- [AMOUNT]))),

@JuanGerardo 

hic
Former Employee
Former Employee

Your initial expression
   SUM(DECODE(Rcount,0,DECODE(H.documentno,NULL,(C.gross- C.amont),0),0))
basically says the sum of "IF Rcount=0 and H.documentno is NULL THEN (C.gross- C.amont) ELSE 0". Right?

That can be written as
   Sum(If(Rcount=0 and IsNull(H.documentno),RangeSum(C.gross,-C.amont),0))
The RangeSum() is needed if C.gross or C.amont can be NULL.

Then you change places of (Gross-Amount) and 0. I assume that the latter is what you want. Then you could write
   Sum(If(Rcount<>0 and not IsNull(H.documentno),RangeSum(C.gross,-C.amont),0))

Introducing set analysis can cause problems:
* You cannot test for NULL in a set expression.
* Numeric selections need to match the format used.
* Unions between conditions can be tricky

But the following could work:

sum (
   {<
   [Year] = {"$(vYear)"},
   [Rcount] -= {">=0<=0"}, // A format independent search that excludes 0
   [Table1.Flag] = {'USA'},
   [table2.Flag] = {'USA'}
   >
   + // The union between the two set modifiers
   <
   [Year] = {"$(vYear)"},
   [documentno] = {"*"}, // A search for ANY value, that excludes NULL
   [Table1.Flag] = {'USA'},
   [table2.Flag] = {'USA'}
   >}
   RangeSum(GROSS,-AMOUNT)
)

HIC

capriconuser
Creator
Creator
Author

i need expression for both below codes

 

for this

 

SUM(DECODE(Rcount,0,DECODE(documentno,NULL,(gross- amount),0),0))

 

and also for this

 

SUM(DECODE(Rcount,0,DECODE(documentno,NULL,0,(gross-amount)),(gross- amount)))

 

 

so for first SQL statement  try this 

 

sum({<[Year] = {"$(=vYear)"},[Rcount ] = {">0"},[Table1.Flag] = {'USA'},[Table2.Flag] = {'USA'} >}if( Rcount = 0,if( isNull(H.documentno), C.gross - C.amont, 0) ,0))

 

and for 2nd statement I try this 

 

 sum({<[Year] = {"$(=vYear)"},[Rcount ] = {">0"},[Table1.Flag] = {'USA'},[Table2.Flag] = {'USA'} >} if(Rcount = 0, if(isNull([documentno]),0,
(gross- amount)),(gross- amount)),0)

 

but this shows an error

@hic  so your sense expression is for which statement 

hic
Former Employee
Former Employee

If you want them as two statements, the first one has the following logic

Henric_Cronström_0-1618903699586.png

and I would use

 

sum (
   {<
   [Rcount] = {">=0<=0"} // A format independent search that matches 0
   >}
   If(IsNull(documentno),RangeSum(gross,-amount))
)

 

and the second has the following logic

Henric_Cronström_1-1618904364766.png

 

sum (
   {<
   [Rcount] -= {">=0<=0"} // A format independent search that excludes 0
   >
   + // The union between the two set modifiers
   <
   [documentno] = {"*"} // A search for ANY value, that excludes NULL
   >}
   RangeSum(gross,-amount)
)

 

In addition you can have other conditions in your set expression, but I haven't included them since you don't have them in the original expression.

HIC

capriconuser
Creator
Creator
Author

is this   rangesum(gross,-amount) or 

 

rangesum(gross-amount)

 

 @hic beacuse in SQL i minus between gross and amount

hic
Former Employee
Former Employee

Rangesum(gross, -amount)

You could use "gross-amount", but then there is a risk of incorrect calculations. If one of the two is NULL, Rangesum() will treat this as zero, whereas a normal addition/subtraction will return NULL:

10 - NULL    =>     NULL

Rangesum(10, NULL)  =>  10