Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

vkish16161
Contributor III

Weird behavior in the division operation

All,

I have a calculation like this:

(Both Numerator and Denominator work individually... but their division doesn't work)

Sum(Aggr(if(Sum([Is Engaged?])/(Count(distinct [Month Year])*4) >= 2,1,0) , [Party ID]))

/

Sum(Aggr(1,[Party ID])) // same as Count (distinct [Party ID])



What I have tried:


Put numerator and denominator separately in a variable and do the division on variables. Doesn't work


Use the div function.


Hoping I didn't do any silly mistake


stalwar1

9 Replies

Re: Weird behavior in the division operation

Don't see anything wrong here... are you using these in a variable and then doing the division through a variable?

vkish16161
Contributor III

Re: Weird behavior in the division operation

Hey Sunny,

I tried that as well. Do you think this could be a bug? Weird thing is that the numerator and denominator work well individually in KPI boxes.

Also I've noticed that....

Sum(Aggr(1, [Party ID]))  is yielding 1 more than Count(distinct [Party ID])


for e.g...


Sum(Aggr(1, [Party ID]))    =101


Count(distinct [Party ID])  =100

Shouldn't both be the same?

stalwar1

Re: Weird behavior in the division operation

I would have thought that the two give the same number... not sure but may be there is a null Party ID, which is getting counted when using Sum(Aggr())...

Coming back to your division... would you be able to share a sample to check out?

vkish16161
Contributor III

Re: Weird behavior in the division operation

"I would have thought that the two give the same number... not sure but may be there is a null Party ID, which is getting counted when using Sum(Aggr())..."


How can I exclude nulls in the Aggr? Sum({<[Party ID] - = {"*"}>} Aggr(1, [Party ID]))


Will provide sample data soon.


stalwar1

Re: Weird behavior in the division operation

May be this

Sum({<[Party ID] = {"*"}>} Aggr(1, [Party ID]))

vkish16161
Contributor III

Re: Weird behavior in the division operation

Thanks bro. Will check it out.

vkish16161
Contributor III

Re: Weird behavior in the division operation

lol. Things got weirder... The following nonsensical tweak made it work.

Variables:

numer  =  (Sum(Aggr(if(Sum([Is Engaged?])/(Count(distinct [Month Year])*4) >= 2,1,0) , [Party ID])) *2 )

/

denom =  ( Count (distinct [Party ID]) * 2)



Expression:


$(numer) / $(denom)


Suspect:  [Is Engaged?] is of Dual type. (Used dual function here)



stalwar1


Re: Weird behavior in the division operation

Difficult to say without looking at this...

sasiparupudi1
Honored Contributor III

Re: Weird behavior in the division operation

Try with a bracket in the numerator

(

Sum(Aggr(if(Sum([Is Engaged?])/(Count(distinct [Month Year])*4) >= 2,1,0) , [Party ID]))

)

/

Sum(Aggr(1,[Party ID]))

Community Browser