Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
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: 
muhammadasfand
Contributor II
Contributor II

Confusion with using Sum function for different units

Hi,

i have the following expression that is causing some issues in Count.

Sum({<TransDate={'>=$(=MonthStart(today(),-12))<=$(=MonthEnd(today(),-1))'}>}$(UnitValue))

$(UnitValue) is a variable that either passes 1 or a value of TEUs e.g. if($(vUnits)=0,TEUs,1)

In case of passing TEUs the sum comes perfect whereas while passing 1, i just want the sum function to behav like count function and just gives a count of all rows but its giving a bigger count than it should be. My problem is i have to stick with Sum in my expression.

Any suggestions?

Thanks,

1 Solution

Accepted Solutions
ogautier62
Specialist II
Specialist II

Hi,


with 1 :

it will count all rows of your database I think because you have no field

with that :

if($(vUnits)=0,TEUs,TEUs-TEUs+1)

it will count all not null rows of TEUs

(for the fun)

prefer Sunny's solution it's clean


View solution in original post

4 Replies
sunny_talwar

May be you can do this

If($(vUnits) = 0,

Sum({<TransDate={'>=$(=MonthStart(today(),-12))<=$(=MonthEnd(today(),-1))'}>} TEUs),

Count({<TransDate={'>=$(=MonthStart(today(),-12))<=$(=MonthEnd(today(),-1))'}>} 1))

ogautier62
Specialist II
Specialist II

Hi,


with 1 :

it will count all rows of your database I think because you have no field

with that :

if($(vUnits)=0,TEUs,TEUs-TEUs+1)

it will count all not null rows of TEUs

(for the fun)

prefer Sunny's solution it's clean


muhammadasfand
Contributor II
Contributor II
Author

You are right about it and i have already considered it the last solution. Ideally i want to do it using Sum() as i have so much conditional expressions and i don't want to do it that way it will increase a lot of code.

muhammadasfand
Contributor II
Contributor II
Author

That looks cool and seem to have worked.